Skip to content

Commit

Permalink
Replace error for schema missmatch with first sub-error instead of re…
Browse files Browse the repository at this point in the history
…placing all errors with first error's sub-errors.
  • Loading branch information
ssipos90 committed Dec 4, 2019
1 parent eb5e572 commit 539cdd5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ function getValidator (options, schema) {
}

if (!validation.valid) {
var errors = validation.errors;
var firstError = validation.errors[0];
if (firstError.message.indexOf('not match any schemas') >= 0 && firstError.subErrors && firstError.subErrors.length > 0) {
firstError = firstError.subErrors[0];
errors = firstError.subErrors;
}
var errors = validation.errors.map(error => {
if (error.message.indexOf('not match any schemas') >= 0 && error.subErrors && error.subErrors.length > 0) {
return error.subErrors[0];
} else {
return error;
}
});
var firstError = errors[0];

return new ValidationError(firstError.dataPath + ' => ' + firstError.message, errors);
}

Expand Down

0 comments on commit 539cdd5

Please sign in to comment.