@mantris/appify
Version:
Very opinionated Node.js API boilerplate as module.
21 lines (16 loc) • 384 B
JavaScript
const { HttpError } = require('@mantris/commons')
const ERROR_CODE = 'INTERNAL_SERVER_ERROR'
/**
* @returns {Function} Middleware.
*/
module.exports = () => {
return (err, req, res, next) => {
if (err instanceof HttpError) {
return next(err)
}
return next(
new HttpError.InternalServerError(ERROR_CODE, err.message, err.stack)
)
}
}