Reputation: 758
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); } has no method 'error'
what am I doing wrong? I cant get error handling to work.
Upvotes: 1
Views: 1654
Reputation: 13106
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
Upvotes: 3