我在快速錯誤處理時遇到了問題。這是我的服務器配置。NodeJs ExpressJS錯誤處理故障
server.use(express.static(__dirname + '/public'));
server.use(server.router);
server.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
server.use(express.bodyParser());
然後我嘗試添加這行代碼
server.error(function(err, req, res, next){
if (err instanceof NotFound) {
res.render('404.jade');
} else {
next(err);
}
});
然後在我的控制檯,我得到這個消息,
對象功能的應用程序(REQ,RES){app.handle( req,res); }沒有方法'錯誤'
我做錯了什麼?我不能得到錯誤處理工作。
檢查我的答案相關的問題:http://stackoverflow.com/questions/10170857/can-i-reuse-the-express-js-error-view/10556093#10556093 – Pickels