joi
joi copied to clipboard
how don't use custom error message ?
Context
- node version:
- module version:
- environment (e.g. node, browser, native):
- used with (e.g. hapi application, another framework, standalone, ...):
- any other relevant information:
How can we help?
//Insert your joi schema here
Joi.object({
age: Joi.number().required().messages({'age': test age required'}),
})
//Insert data to validate here
{
}
result:
Validation Error: "age" is required
why error message is not test age required
?
@syymo you can do it this way:
Joi.object({ age: Joi.number().required().error(new Error('test age required')), })
Another way you could display the same message is by doing:
Joi.object({ age: Joi.number().required().messages({'any.required': 'test age required'}), })
Joi.object({
age: Joi.number().required().messages({'any.required': 'test age required'}),
})
{ "age" : " " }
can i change the message to age is required ??
Your failing rule in this case is number.base
, as shown in the details of the error, so you need to change that message.