Let users return Error objects from validators

pull/4/head
Sven Slootweg 4 years ago
parent 955fec8ab1
commit d13a4a8235

@ -40,9 +40,11 @@ module.exports.compose = function composeValidators(validators) {
} else { } else {
throw new Error(`The 'errors' in a validationResult must be an array`); throw new Error(`The 'errors' in a validationResult must be an array`);
} }
} else if (result instanceof Error) { } else if (result instanceof Error && matchValidationError(result)) {
// We could interpret returned Errors as either values or a throw substitute. Let's wait for users to file issues, so that we know what people *actually* need here. return {
throw new Error(`It is currently not allowed to return an Error object from a validator. If you have a reason to need this, please file a bug!`); errors: [ result ],
newValue: undefined
};
} else { } else {
return { return {
errors: [], errors: [],

Loading…
Cancel
Save