【发布时间】:2015-02-26 00:17:33
【问题描述】:
我正在使用节点,我尝试重定向显示 404 和 500 错误。
现在我有这个工作正常的代码:
/* ... Some require here ... */
var app = module.exports = express();
/* ... Some app config here */
// Setup my routes
routes.setup(app);
// Handling 404 errors
app.use(function(req, res) {
res.end("Oups !", 404);
});
// Handling 500 errors
app.use(function(error, req, res, next) {
console.log("Display error : ", error);
res.end("Oups !", 500);
});
// Start server
var server = app.listen(config.PORT);
现在,如果我在我的代码上执行throw new Error("An error here"); 在console.log 上我刚刚得到一个字符串:
Display error : An error here
如果我删除处理错误 500 的部分,我会在控制台日志中自动获得错误来自何处的描述:
Error: An error here
at Layer.handle (/.../app.js:94:7)
at trim_prefix (/.../node_modules/express/lib/router/index.js:226:17)
at c (/.../node_modules/express/lib/router/index.js:198:9)
at Function.proto.process_params (/.../node_modules/express/lib/router/index.js:251:12)
at next (/.../node_modules/express/lib/router/index.js:189:19)
at next (/.../node_modules/express/lib/router/index.js:166:38)
at next (/.../node_modules/express/lib/router/index.js:166:38)
at next (/.../node_modules/express/lib/router/index.js:166:38)
at next (/.../node_modules/express/lib/router/index.js:166:38)
at Layer.handle (/.../app.js:50:5)
我怎样才能获得有关投掷地点的信息?
谢谢大家!
【问题讨论】:
标签: node.js express error-handling