-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 14.11.0
- module version: 17.4
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): standalone
- any other relevant information: Using this external API https://joi.dev/api/?v=17.4.0#anyexternalmethod-description
How can we help?
Scenario: When user submit input, I will check is it the user id exist in the database. If not exist it will return a custom error message. The following is my sample code snippet.
const userId = Joi.number()
.integer()
.required()
.external(async (value) => {
let user = await userModel.selectOne({ id: value });
if (!user) {
throw new AppError(AppError.INVALID_USER_ID);
}
})
.error(() => { throw new AppError(AppError.INVALID_USER_ID) });
const schema = Joi.object({
userId
});
schema.validateAsync(userInput);Expected output:
"message": "Invalid user id."
Actual output:
"message": "Invalid user id." (userId)
It automatically add the field name into my error message. Is there any way to remove it?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect