[英]NodeJs ExpressJS Error Handling Trouble
I am having trouble with express Error handling. 我遇到快速错误处理问题。 Here is my configuration for the server. 这是我对服务器的配置。
server.use(express.static(__dirname + '/public'));
server.use(server.router);
server.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
server.use(express.bodyParser());
Then I try adding this line of code 然后我尝试添加这行代码
server.error(function(err, req, res, next){
if (err instanceof NotFound) {
res.render('404.jade');
} else {
next(err);
}
});
Then in my console, I get this message, 然后在我的控制台中,我收到此消息,
Object function app(req, res){ app.handle(req, res); 对象功能app(req,res){app.handle(req,res); } has no method 'error' 没有方法'错误'
what am I doing wrong? 我究竟做错了什么? I cant get error handling to work. 我无法让错误处理工作。
What version of express are you using? 你使用什么版本的快递?
Because there is a new 3.x version ( still in alpha stage ) out that changed quite a lot of stuff , and things such as the error handling is changed 因为有一个新的3.x版本( 仍处于alpha阶段 ),它改变了很多东西 ,并且诸如错误处理之类的东西被改变了
Check out the migration guide from 2.x to 3.x 查看从2.x到3.x的迁移指南
The page is a work in progress, consider moving back to 2.x or waiting for a better 3.x documentation and migration guide 该页面正在进行中,请考虑返回2.x或等待更好的3.x文档和迁移指南
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.