diff --git a/lib/validator.js b/lib/validator.js index 93e4192..6ef0327 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -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); }