-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Context
- node version: v10.13.0
- joi version: 16.0.0-rc1
- environment (node, browser): node
- used with (hapi, standalone, ...): standalone
- any other relevant information:
What are you trying to achieve or the steps to reproduce ?
const myValidator = Joi.string().trim().regex(/someregex/)
.error(errors => {
let error = errors[0];
if (error.type === 'string.regex.base') {
error.message = 'my new error message'
}
return errors;
})
let { error, value } = Joi.validate(input, {
field1: Joi.array().items(myValidator.min(2).max(64)),
field2: myValidator
})Which result you had ?
When there is an error in field2 (not array), I am getting what I expected.
But when there is an error inside the array (field1), error is null while value will look like:
{
field1: [
// instance of Report with properties such as isJoi, context, message, etc
isJoi: {...}
],
field2: 'original value'
}What did you expect ?
let { error, value } = Joi.validate(input, {
field1: Joi.array().items(myValidator.min(2).max(64)),
field2: myValidator
})I expect error to be the error message
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect