3👍
✅
Have a look to the Express error handling documentation:
http://expressjs.com/en/guide/error-handling.html
It explains how handle synchronous and asynchronous errors.
Basically, you need to pass your error as argument of the next() function and provide a personalized error handler or use the default one:
app.use(function(err, req, res, next) {
console.error(err.stack);
res.status(500).send('Internal Server Error');
});
This code must be placed after all other calls to “use”.
Source:stackexchange.com