21 lines
422 B
TypeScript
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);
|
|
}
|
|
}
|