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,
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
Check out the migration guide from 2.x to 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.