Instead of manually creating an error, you can delegate this error, as shown below.
return next(err);
And your mistake will go deep into all the routes defined until it finds routes with a signature.
app.use(function (err, req, res, next) { });
You can see the err argument in the above route.
Ideally, you can use below two methods for the DEVELOPMENT and PRODUCTION environment.
if (process.env.NODE_ENV === 'development') { app.use(function (err, req, res, next) { res.status(err.status || 500); logger.log('info', err.message + " expected URL was " + req.url); res.status(err.status).send(err.status, { message: err.message, error : err }); }); } app.use(function (err, req, res, next) { res.status(err.status || 500); logger.log('error', err.message + " expected URL was " + req.url); res.status(err.status).send(err.status, { message: err.message, error : {} }); });
You can capture the actual bug settlement there.
source share