module.exports = app => { process.on('uncaughtException', err => { console.error(`Caught exception: ${err}`); }); process.on('warning', () => { console.error(`My warning err`); }); app.use(function(error, request, response, next) { if (!error.httpStatusCode) return next(error); response.status(error.httpStatusCode); response.json({ httpStatusCode: error.httpStatusCode, name: error.name, message: error.message, }); }); };