diff --git a/lib/error/validation.js b/lib/error/validation.js index fb251bd94f1..950513575ed 100644 --- a/lib/error/validation.js +++ b/lib/error/validation.js @@ -17,16 +17,15 @@ const util = require('util'); function ValidationError(instance) { this.errors = {}; - this.name = 'ValidationError'; this._message = ''; + MongooseError.call(this, this._message); if (instance && instance.constructor.name === 'model') { this._message = instance.constructor.modelName + ' validation failed'; } else { this._message = 'Validation failed'; } - - MongooseError.call(this, this._message); + this.name = 'ValidationError'; if (Error.captureStackTrace) { Error.captureStackTrace(this);