errorForAll
errorForAll(message, [ctx])
Effect
error
set the custom error message for the restrict before error calling position. errorForAll
set custom error message for all restrict.
Since
>=1.3.0
Arguments
message
(string | function)
- The custom error message. If it's a function, the function should return a string, respect the custom error message. The function has an argument: the original validate error object.[ctx]
(*) - The execution context ofmessage
when it's a function.
Example
const schema = racoon
.number()
.error('error 1')
.int()
.min(2)
.error('error 2')
.max(5)
.errorForAll('error for all');
schema.validate('abc'); // fail, error message: 'error 1'
schema.validate(3.2); // fail, error message: 'error for all'
schema.validate(1); // fail, error message: 'error 2'
schema.validate(6); // fail, error message: 'error for all'
Last updated
Was this helpful?