Initial auth library commmit
This commit is contained in:
13
lib/middleware/errorHandler.ts
Normal file
13
lib/middleware/errorHandler.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { Context, Next } from "koa";
|
||||
|
||||
export const errorHandler = async (ctx: Context, next: Next) => {
|
||||
try {
|
||||
await next();
|
||||
} catch (error: any) {
|
||||
ctx.status = error.statusCode || error.status || StatusCodes.INTERNAL_SERVER_ERROR;
|
||||
error.status = ctx.status;
|
||||
ctx.body = { error };
|
||||
ctx.app.emit('error', error, ctx);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user