-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support
Milestone
Description
Context
- node version: 8.x
- joi version: latest
- environment (node, browser): node
- used with (hapi, standalone, ...): standalone
What are you trying to achieve or the steps to reproduce ?
const userSchema = Joi.object().keys({
city: Joi.object().keys({
id: Joi.number().required().error(new Error('invalid city id')),
}).required().error(new Error('city is required')),
});Which result you had ?
it returns 'city is required' unless all the nested objects are valid.
What did you expect ?
display error for each part.
while this works without .error(), I want to be able to send custom error messages for each part.
For example:
const userSchema = Joi.object().keys({
city: Joi.object().keys({
id: Joi.number().required().error(new Error('invalid city id')),
}).required().error(new Error('city is required')),
});
userSchema.validate({ city: { id: 'asfasf' } }); // returns 'city is required', while I'm expecting it to return 'invalid city id'Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support