Skip to content

Commit

Permalink
docs(error): add more detail about the ValidatorError class, includin…
Browse files Browse the repository at this point in the history
…g properties

Fix #8346
  • Loading branch information
vkarpov15 committed Nov 21, 2019
1 parent 40dbc06 commit 67babb8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/error/index.js
Expand Up @@ -102,7 +102,32 @@ MongooseError.CastError = require('./cast');
MongooseError.ValidationError = require('./validation');

/**
* A `ValidationError` has a hash of `errors` that contain individual `ValidatorError` instances
* A `ValidationError` has a hash of `errors` that contain individual
* `ValidatorError` instances.
*
* ####Example:
*
* const schema = Schema({ name: { type: String, required: true } });
* const Model = mongoose.model('Test', schema);
* const doc = new Model({});
*
* // Top-level error is a ValidationError, **not** a ValidatorError
* const err = doc.validateSync();
* err instanceof mongoose.Error.ValidationError; // true
*
* // A ValidationError `err` has 0 or more ValidatorErrors keyed by the
* // path in the `err.errors` property.
* err.errors['name'] instanceof mongoose.Error.ValidatorError;
*
* err.errors['name'].kind; // 'required'
* err.errors['name'].path; // 'name'
* err.errors['name'].value; // undefined
*
* Instances of `ValidatorError` have the following properties:
*
* - `kind`: The validator's `type`, like `'required'` or `'regexp'`
* - `path`: The path that failed validation
* - `value`: The value that failed validation
*
* @api public
* @memberOf Error
Expand Down

0 comments on commit 67babb8

Please sign in to comment.