thrownewError(`Must specify an array of alternatives`);
@ -46,15 +48,13 @@ module.exports = function (alternatives) {
return(error.path.length===0);
});
if(nestedErrors.length>0){
// At least one of the alternatives *did* match, but it failed somewhere further down the tree. Chances are that the user intended to match that branch, so we pretend that the other alternatives don't exist, and pass through the original error(s).
// One of the alternatives *did* match, but it failed somewhere further down the tree, and we don't have any errors originating from *other* nested rules. Chances are that the user intended to match the failing branch, so we pretend that the other alternatives don't exist, and pass through the original error(s).
returnvalidationResult({errors:nestedErrors});
}else{
letalternativesList=sameLevelErrors
.map((error)=>`"${error.message}"`)
.join(", ");
thrownewValidationError(`Must satisfy at least one of: ${alternativesList}`,{errors:sameLevelErrors});
thrownewValidationError(`Must satisfy at least one of:`,{subErrors:allErrors});