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

30 lines
743 B
TypeScript
Raw Normal View History

///<reference path="../../typings/main.d.ts"/>
import {RenderingMWs} from "../middlewares/RenderingMWs";
2016-05-06 16:48:51 +08:00
import {Error, ErrorCodes} from "../../common/entities/Error";
export class ErrorRouter{
constructor(private app) {
this.addApiErrorHandler();
2016-04-22 19:23:44 +08:00
this.addGenericHandler();
}
private addApiErrorHandler() {
this.app.use("/api/*",
RenderingMWs.renderError
);
};
private addGenericHandler() {
this.app.use((err, req, res, next) => {
//Flush out the stack to the console
console.error(err.stack);
2016-05-06 16:48:51 +08:00
next(new Error(ErrorCodes.SERVER_ERROR,"Unknown server side error"));
},
RenderingMWs.renderError
);
}
}