salix/print/lib/errorHandler.js

22 lines
555 B
JavaScript
Raw Normal View History

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