我用了快一个自定义错误页,为解释在这里.
但是当我这样做时,我只看到错误信息.我想获取默认Express错误处理程序(堆栈跟踪等)中显示的相同信息,以便我可以:
我该怎么做呢?
这是来自@ generalhenry的答案的修改版本.您可以访问堆栈跟踪,err.stack以便在"500"视图中传递它并在其上执行一些奇特的CSS样式.
app.use(function(err, req, res, next) {
if (err instanceof NotFound) {
res.render('errors/404');
} else {
res.render('errors/500', {error: err, stack: err.stack});
}
});
function NotFound() {
this.name = "NotFound";
Error.call(this, msg);
Error.captureStackTrace(this, arguments.callee);
}
// below all route handlers
// If all fails, hit em with the 404
app.all('*', function(req, res){
throw new NotFound;
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6217 次 |
| 最近记录: |