15 lines
462 B
TypeScript
15 lines
462 B
TypeScript
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);
|
|
}
|
|
}
|