2016-03-26 18:19:10 +08:00
|
|
|
///<reference path="../../typings/main.d.ts"/>
|
|
|
|
|
|
|
|
import {RenderingMWs} from "../middlewares/RenderingMWs";
|
|
|
|
|
|
|
|
export class ErrorRouter{
|
|
|
|
constructor(private app) {
|
|
|
|
|
2016-04-10 00:06:29 +08:00
|
|
|
this.addApiErrorHandler();
|
2016-04-22 19:23:44 +08:00
|
|
|
this.addGenericHandler();
|
2016-03-26 18:19:10 +08:00
|
|
|
}
|
|
|
|
|
2016-04-10 00:06:29 +08:00
|
|
|
private addApiErrorHandler() {
|
2016-03-26 18:19:10 +08:00
|
|
|
this.app.use("/api/*",
|
|
|
|
RenderingMWs.renderError
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2016-04-10 00:06:29 +08:00
|
|
|
private addGenericHandler() {
|
|
|
|
this.app.use((err, req, res, next) => {
|
|
|
|
res.status(500).send('Houston, we have a problem!');
|
|
|
|
|
|
|
|
//Flush out the stack to the console
|
|
|
|
console.error(err.stack);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-03-26 18:19:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|