backend/src/middlewares/ErrorHandler.ts
2020-11-27 21:16:15 +01:00

21 lines
422 B
TypeScript

import {
Middleware,
ExpressErrorMiddlewareInterface
} from "routing-controllers";
@Middleware({ type: "after" })
export class ErrorHandler implements ExpressErrorMiddlewareInterface {
public error(
error: any,
request: any,
response: any,
next: (err: any) => any
) {
if (response.headersSent) {
return;
}
response.json(error);
}
}