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

Return context with errors. #462

Closed
jkyle opened this issue Oct 28, 2014 · 1 comment
Closed

Return context with errors. #462

jkyle opened this issue Oct 28, 2014 · 1 comment
Labels
feature New functionality or improvement
Milestone

Comments

@jkyle
Copy link

jkyle commented Oct 28, 2014

It would be helpful for constructing error messages (outside of Joi) to have the context for each error in the details array. For example, if

{
  length: Joi.number().min(3)
}

generates an validation error, all we know from the error is

{
  message: "length must be larger than or equal to 3",
  path: "length",
  type: "number.min"
}

If I want to pass the error to a separate localization library (that doesn't use the {{ key }} format) it's difficult to extract the min limit, but that information is present if we add the context to the detail object:

{
  message: "length must be larger than or equal to 3",
  path: "length",
  type: "number.min",
  context: {
    key: "length",
    limit: 3
  }
}
@Marsup Marsup closed this as completed in 8db651d Nov 22, 2014
@Marsup Marsup self-assigned this Nov 22, 2014
@Marsup Marsup added this to the 5.0.0 milestone Nov 22, 2014
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants