Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joi.external() error message #2600

Closed
ShyeChern opened this issue Apr 25, 2021 · 0 comments · Fixed by #2651
Closed

Joi.external() error message #2600

ShyeChern opened this issue Apr 25, 2021 · 0 comments · Fixed by #2651
Assignees
Labels
bug Bug or defect
Milestone

Comments

@ShyeChern
Copy link

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

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?

Marsup added a commit that referenced this issue Aug 5, 2021
@hueniverse hueniverse added the bug Bug or defect label Dec 1, 2021
@hueniverse hueniverse added this to the 17.5.0 milestone Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants