Small Node.js utility to normalize mongoose errors.
$ npm install mongoose-error --save
mongoose-error
normalize the error message to include the first validation error, and can also catch mongo duplicate key.
const mongooseError = require('mongoose-error');
user.save()
.then(
() => {
console.log('saved!');
},
(err) => {
throw mongooseError(err, {
DuplicateKey: 'An user with this username already exist'
});
}
);