Reputation: 5750
In express app, I researched that we can handle error using something like this:
// app.js
app.use(function (error, req, res, next) {
// Handle errors
});
my questions are:
Thanks
Upvotes: 0
Views: 159
Reputation: 13598
Yes. Middleware with arity of 4 (that is: err, req, res, next
) are error handlers, and will be called when there's an error.
Errors may be uncaught exceptions in your other middleware, or explicitly errors that you raise when you call next(err)
instead of next()
with no arguments.
There will be cases when these handlers won't be called. For example: errors that happen in async blocks.
Upvotes: 2