Skip to content

Commit

Permalink
Merge pull request #151 from ssipos90/fix-schema-alternatives-removin…
Browse files Browse the repository at this point in the history
…g-errors

Fix for validation error(s) swallowing
  • Loading branch information
nanov authored Dec 5, 2019
2 parents eb5e572 + eaf7c08 commit 70163db
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(function (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 70163db

Please sign in to comment.