任何一个错误都被认为是一个错误索引。试试这个,
app.use((req: express.Request, res: express.Response, next: Function) => {
let err: any = new Error('Not Found');
err.status = 404;
next(err);
});
let error = new ectrl.ErrorController();
app.use('*', error.errorAction);
return app;
}
你的ectrl在哪
export module Controller {
export class ErrorController extends ctrl.Controller {
constructor() {
super();
}
errorAction(err: any, req: Request, res: Response, next: Function) {
let data = {
message: err.message,
error: err,
title: err.message,
layout: path.join(__dirname, '..', 'views', 'layouts', 'layout.hbs')
};
res.status(err.status || 500);
res.render('error/error', data);
}
}
}