Added errorhandler middleware

This commit is contained in:
Nicolai Ort 2021-01-30 17:27:01 +01:00
parent 9d62225478
commit 6539fd7855
1 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import { ExpressErrorMiddlewareInterface, Middleware } from "routing-controllers";
/**
* Our Error handling middlware that returns our custom httperrors to the user.
*/
@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);
}
}