-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support
Description
Support plan
- which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
- is this issue currently blocking your project? yes
- is this issue affecting a production system? no
Context
- node version: 12
- module version: 17.1.1
- environment (e.g. node, browser, native): node
- any other relevant information: I wrote a custom external validator but I got a problem where I need to throw a Joi validation error. the issue is I am not able to access the context in order to pass labels and keys to the JoiError instance.
// I need to throw similar error to this one so the missing part is the context. in external validator, I know nothing about the current rule (only value) but the key, orignal, and the label are not known
[Error [ValidationError]: "student_id" is not allowed] {
_original: {
subject: 'this is the subject',
student_id: 15
},
details: [
{
message: '"student_id" is not allowed',
path: [ 'student_id' ],
type: 'object.unknown',
context: {
child: 'student_id',
label: 'student_id',
value: '15',
key: 'student_id'
}
}
]
}How can we help?
is there any way to access the context of the current validation rule? something like this
// pass context as another argument
joi.external(async (value, context) => {
record = await Model.query().findOne(column, value);
if (!record) {
throw new JoiError('Record does not exist', [{
message: `resource "${value}" doesn't exist in relation ${Model.name}`,
type: 'any.exist',
context: {
...context
}
}]);
}
})Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support