Skip to content

Commit 70163db

Browse files
authored
Merge pull request #151 from ssipos90/fix-schema-alternatives-removing-errors
Fix for validation error(s) swallowing
2 parents eb5e572 + eaf7c08 commit 70163db

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/validator.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ function getValidator (options, schema) {
4444
}
4545

4646
if (!validation.valid) {
47-
var errors = validation.errors;
48-
var firstError = validation.errors[0];
49-
if (firstError.message.indexOf('not match any schemas') >= 0 && firstError.subErrors && firstError.subErrors.length > 0) {
50-
firstError = firstError.subErrors[0];
51-
errors = firstError.subErrors;
52-
}
47+
var errors = validation.errors.map(function (error) {
48+
if (error.message.indexOf('not match any schemas') >= 0 && error.subErrors && error.subErrors.length > 0) {
49+
return error.subErrors[0];
50+
} else {
51+
return error;
52+
}
53+
});
54+
var firstError = errors[0];
55+
5356
return new ValidationError(firstError.dataPath + ' => ' + firstError.message, errors);
5457
}
5558

0 commit comments

Comments
 (0)