diff --git a/lib/error/validation.js b/lib/error/validation.js index 85b733c48b3..950513575ed 100644 --- a/lib/error/validation.js +++ b/lib/error/validation.js @@ -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; }