I want to send the response
with an error
in my koa app when there is no sessionId
.I explored But didn't get anything helpful for me to do the same. I also used return ctx.throw(401);
for unauthorized
but it is not good, ctx.throw(401);
just sending the "unauthorized", I want to add some specific information and after adding just send the response to the client.
can anyone suggest me what to do the same?
My code is:
index.validateKey = async (ctx, next) => {
await new Promise((resolve, reject) => {
var authorized = ctx.headers.sessionid ? true : false;
if (!authorized) {
return ctx.throw(401); //HERE , I want to send .
}
resolve();
});
await next();
}