http-error-handler.js 378 B

1234567891011121314151617
  1. const { isHttpError } = require('../../../node_modules/http-errors');
  2. module.exports = (err, req, res, next) => {
  3. // handle if the err is a HttpError instance
  4. if (isHttpError(err)) {
  5. const httpError = err;
  6. return res
  7. .status(httpError.status)
  8. .send({
  9. status: httpError.status,
  10. message: httpError.message,
  11. });
  12. }
  13. next(err);
  14. };