1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/routes/ErrorRouter.ts

32 lines
790 B
TypeScript
Raw Normal View History

import {RenderingMWs} from "../middlewares/RenderingMWs";
2016-05-06 16:48:51 +08:00
import {Error, ErrorCodes} from "../../common/entities/Error";
2017-06-04 21:25:08 +08:00
import {Logger} from "../Logger";
2016-12-27 06:36:38 +08:00
import Request = Express.Request;
import Response = Express.Response;
2016-05-09 23:04:56 +08:00
export class ErrorRouter {
public static route(app: any) {
this.addApiErrorHandler(app);
this.addGenericHandler(app);
}
private static addApiErrorHandler(app) {
app.use("/api/*",
RenderingMWs.renderError
);
};
private static addGenericHandler(app) {
app.use((err: any, req: Request, res: Response, next: Function) => {
//Flush out the stack to the console
Logger.error(err);
next(new Error(ErrorCodes.SERVER_ERROR, "Unknown server side error"));
},
RenderingMWs.renderError
);
}
}