UNPKG

authorizevi2018

Version:
27 lines (22 loc) 649 B
const httpStatus = require('http-status'); /** * Error handler. Send stacktrace only during development * @public */ const handler = (ex, req, res, next) => { const { status = 500 } = ex; const response = { code: status, message: ex.message || httpStatus[status], errors: ex.errors }; if (ex.stack && process.env.NODE_ENV !== 'development') response.stack = ex.stack; /* Step:: translate message */ response.message = !ex.isTranslated ? res.__(response.message) : response.message; // res.status(status); res.json(response); res.end(); }; exports.handler = handler;