1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/routes/ErrorRouter.ts
2017-07-09 14:23:50 +02:00

31 lines
815 B
TypeScript

import {RenderingMWs} from "../middlewares/RenderingMWs";
import {Error, ErrorCodes} from "../../common/entities/Error";
import {Logger} from "../Logger";
import Request = Express.Request;
import Response = Express.Response;
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("Unexpected error:", err);
next(new Error(ErrorCodes.SERVER_ERROR, "Unknown server side error", err));
},
RenderingMWs.renderError
);
}
}