Added errorhandler middleware
This commit is contained in:
parent
9d62225478
commit
6539fd7855
14
src/middlewares/ErrorHandler.ts
Normal file
14
src/middlewares/ErrorHandler.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user