-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
When I am not passing token or passing invalid token while accessing protected url, it is giving me 401 error with "Unauthorised" message as plain text. I want that it should show error message as json.
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
logerr(err);
ctx.status = err.status || err.code;
ctx.body = {
status: false,
message: err.message,
};
}
});
It is not getting catched in the above function, but it is getting captured in below function.
app.on('error', (err, ctx) => {
logerr('onerr ', err);
if (err.name === "UnauthorizedError") {
ctx.status = 401;
ctx.body = "invalid token...";
}
});
But it is not showing me "Invalid token" message but it is throwing "Unauthorised" error as plain text.
Metadata
Metadata
Assignees
Labels
No labels