Skip to content

Commit e6285ea

Browse files
authored
Merge pull request #8244 from AbdelrahmanHafez/master
Minor refactor to ValidationError
2 parents 13ae085 + d9163f5 commit e6285ea

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/error/validation.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ const util = require('util');
1818
function ValidationError(instance) {
1919
this.errors = {};
2020
this._message = '';
21+
22+
MongooseError.call(this, this._message);
2123
if (instance && instance.constructor.name === 'model') {
2224
this._message = instance.constructor.modelName + ' validation failed';
23-
MongooseError.call(this, this._message);
2425
} else {
2526
this._message = 'Validation failed';
26-
MongooseError.call(this, this._message);
2727
}
2828
this.name = 'ValidationError';
29+
2930
if (Error.captureStackTrace) {
3031
Error.captureStackTrace(this);
3132
} else {
3233
this.stack = new Error().stack;
3334
}
35+
3436
if (instance) {
3537
instance.errors = this.errors;
3638
}

0 commit comments

Comments
 (0)