Context
- node version: 4.4.2
- joi version: 10.5.5
- environment (node, browser):node
- used with (hapi, standalone, ...):standalone
- any other relevant information: Passing custom error instance to Joi().any().error()
What are you trying to achieve or the steps to reproduce ?
Describe your issue here, include schemas and inputs you are validating if needed.
const Joi = require('joi');
const addressSchema = Joi.object().keys({
address: Joi.object().keys({
pin: Joi.number()
.min(100000)
.max(999999)
.error(new Error('pincode is missing'))
.required()
}).error(new Error('address is missing'))
.required()
});
let address ={
"action" : "xyz",
"address":
{
"id": "1",
"title": 'Home'
}
}
Joi.validate(address, addressSchema, (err, value) => console.log(err));
Which result you had ?
address is missing
What did you expect ?
pincode is missing