mongoose-validate-pretty-errors
v1.0.2
Published
the Plugin for Mongoose library that convert validation errors fields format {{fieldName, error}, ...}
Downloads
7
Maintainers
Readme
mongoose-validate-pretty-errors
The plugin for Mongoose that helps converts model validation errors to array of errors. //turns duplicate errors into regular Mongoose validation errors.
Validation errors format:
[
{"name": "Field name", "message": "Error message"}
]
Install
npm install --save mongoose-validate-pretty-errors
Supported versions of Mongoose
Starting from version 1.0.1, this module only supports Mongoose 4.2.8 and upper.
| This package’s version | Supported Mongoose versions | | ----------------------:|:--------------------------- | | 1 | ≥ 4.2.8 |
Supported versions of Node
The module supports Node.js 4, 5, 6, 7 and 8. fill a bug report!
Error validation message
const prettyErrors = require('mongoose-validate-pretty-errors');
const userSchema = mongoose.Schema({});
userSchema.plugin(beautifyUnique);
const User = mongoose.model('Model', userSchema);
try {
const user = await User.save();
} catch {
return {__typename: "Errors", message: e.messages}
}
License
Released under the MIT license. See the full license text.