2019-01-22 13:10:34 +00:00
|
|
|
module.exports = app => {
|
|
|
|
process.on('uncaughtException', err => {
|
2019-01-22 08:55:35 +00:00
|
|
|
console.error(`Caught exception: ${err}`);
|
|
|
|
});
|
|
|
|
|
2019-01-22 13:10:34 +00:00
|
|
|
process.on('warning', () => {
|
2019-01-22 08:55:35 +00:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|