Relish provides "better error message for Hapi.js Joi validation."
However, in large scale applications managing the individual route validatefailAction functions custom messages can become tedious. Even though a common object may be defined in the hapi server's route configuration, this only facilitates common messages.
For example, if you need to have a option which is required on one route but optional on another, it is difficult to change the custom message.
Problem Example
server.route({
method:'POST',
path:'/relish/custom',
options:{
validate:{
payload:{
input:Joi.string().min(3).max(10)
},
/// this is a bulky statement since it is a function call then a pointer to a function.
failAction:Relish({
messages:{
input:'input is required and must be between 3 and 10 characters in length'
}
}).failAction
},
handler: handler
}
});
Solution Example
server.route({
method:'POST',
path:'/example',
options:{
validate:{
payload:{
input:Joi.string().min(3).max(10)
}
},
// hapi standard plugin syntax
plugins:{
chowChow:{
input:'input is required and must be between 3 and 10 characters in length'