Skip to content

Commit

Permalink
Merge pull request #8244 from AbdelrahmanHafez/master
Browse files Browse the repository at this point in the history
Minor refactor to ValidationError
  • Loading branch information
vkarpov15 committed Oct 14, 2019
2 parents 13ae085 + d9163f5 commit e6285ea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/error/validation.js
Expand Up @@ -18,19 +18,21 @@ const util = require('util');
function ValidationError(instance) {
this.errors = {};
this._message = '';

MongooseError.call(this, this._message);
if (instance && instance.constructor.name === 'model') {
this._message = instance.constructor.modelName + ' validation failed';
MongooseError.call(this, this._message);
} else {
this._message = 'Validation failed';
MongooseError.call(this, this._message);
}
this.name = 'ValidationError';

if (Error.captureStackTrace) {
Error.captureStackTrace(this);
} else {
this.stack = new Error().stack;
}

if (instance) {
instance.errors = this.errors;
}
Expand Down

0 comments on commit e6285ea

Please sign in to comment.