1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00
pigallery2/backend/routes/ErrorRouter.ts

30 lines
824 B
TypeScript
Raw Normal View History

import {RenderingMWs} from "../middlewares/RenderingMWs";
2016-05-06 10:48:51 +02:00
import {Error, ErrorCodes} from "../../common/entities/Error";
2016-12-26 23:36:38 +01:00
import Request = Express.Request;
import Response = Express.Response;
2016-05-09 17:04:56 +02:00
export class ErrorRouter {
2016-12-26 23:36:38 +01:00
constructor(private app: any) {
this.addApiErrorHandler();
2016-04-22 13:23:44 +02:00
this.addGenericHandler();
}
private addApiErrorHandler() {
this.app.use("/api/*",
RenderingMWs.renderError
);
};
private addGenericHandler() {
2016-12-26 23:36:38 +01:00
this.app.use((err: any, req: Request, res: Response, next: Function) => {
2016-05-09 17:04:56 +02:00
//Flush out the stack to the console
console.error(err.stack);
next(new Error(ErrorCodes.SERVER_ERROR, "Unknown server side error"));
},
RenderingMWs.renderError
2016-05-06 10:48:51 +02:00
);
}
}