salix/print/lib/errorHandler.js

22 lines
548 B
JavaScript

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,
});
});
};