I am using Joi to validate the schema and I are not using Hapi.
I am writing a test case where my joi schema should return an error. Below is my schema
const testSchema = Joi.object().keys({
name: Joi.string().required(),
data: Joi.array().min(1).max(8).required(),
});
My current payload
const currentPayload = {
data: ['1', '2'],
};
and my simple validation is
try {
const result = Joi.validate(currentPayload, testSchema);
} catch (err) {
console.log(err);
}
Now, this err
just contains a canned message without details. To get detailed message, I need to use failAction
as described here
What I have understood so far is that failAction
is hapi function and not joi.
Any ideas how can I get detailed error message to work
Edit:
Here is how the err
object looks like
This is really embarrassing. This error gets thrown if the schema mentioned in the Joi.validate
in invalid. In my case it was undefined
as I was referencing it incorrectly from another file :(
the good part is now I know when Joi will throw an exception :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.