Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var router = require('express').Router();
- router.use('/', require('./users'));
- // catch validation errors thrown by Mongoose and return an object with
- // all these errors
- router.use(function(err, req, res, next) {
- if (err.name === 'ValidationError') {
- return res.status(422).json({
- errors: Object.keys(err.errors).reduce(function(errors, key) {
- errors[key] = err.errors[key].message;
- return errors;
- }, {})
- });
- }
- return next(err);
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment