Skip to content

Return context with errors. #462

@jkyle

Description

@jkyle

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
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions