-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Context
- node version: 7.7.1
- joi version: 10.3.1
- environment (node, browser): node
- used with (hapi, standalone, ...): standalone
- any other relevant information:
What are you trying to achieve or the steps to reproduce ?
I try to have a custom error message if a parameter is required conditionally and it is not provided in input. For example for the schema below at least one of the start or match parameters should be provided. So I made start required if match is not provided, and I want to tell user, that one of them should be provided instead of start is required..
const schema = {
ignore: Joi.array().items(Joi.string()).optional(),
types: Joi.object().pattern(/\w+/, Joi.array().items(Joi.string())).optional(),
rules: Joi.array().items(Joi.object().keys({
type: Joi.string(),
start: Joi.array().items(Joi.string()).when('match', { is: Joi.empty(), then: Joi.required().error(new Error('CUSTOM MESSAGE')), otherwise: Joi.optional() }),
match: Joi.alternatives().try(Joi.string(), Joi.object().type(RegExp)).optional(),
})),
};
const config = {
ignore: ['space'],
types: {
identifier: ['select'],
conjunction: ['and', 'or'],
},
rules: [
{ type: 'sil' },
],
};
Joi.assert(config, schema);Which result you had ?
Exception is thrown for:
TypeError: error.annotate is not a function
What did you expect ?
I expected my custom exception:
CUSTOM MESSAGE
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect