Skip to content

Commit

Permalink
Minor refactor to ValidationError
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez committed Oct 13, 2019
1 parent 13ae085 commit cec9dda
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/error/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ const util = require('util');

function ValidationError(instance) {
this.errors = {};
this.name = 'ValidationError';
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';

MongooseError.call(this, this._message);

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

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

0 comments on commit cec9dda

Please sign in to comment.