error_helpers.js 287 B

12345678910111213141516
  1. 'use strict';
  2. module.exports = (req, res, next) => {
  3. res.bad_request = (msg) => {
  4. if (req.accepts('text/html')) {
  5. res.status(400).render('error', {
  6. message: msg
  7. });
  8. } else {
  9. res.status(400).json({
  10. "error": msg
  11. });
  12. }
  13. }
  14. next();
  15. }