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

Validation Exception Metadata #554

Open
justinsaliba opened this issue Jul 10, 2020 · 0 comments
Open

Validation Exception Metadata #554

justinsaliba opened this issue Jul 10, 2020 · 0 comments

Comments

@justinsaliba
Copy link

Hi,

I'd like to request a small feature that would allow Mule APIs to return more verbose and helpful responses to API consumers.

I would like to request that APIKit exceptions would contain metadata about why validation failed. Currently, there is a simple error message, which works fine as an API response, however that's about as far as developers can take it. To give you an example, here's the exception message thrown by APIKit when query parameter validation fails:

org.mule.module.apikit.api.exception.InvalidQueryParameterException: Invalid value '2020-08-011' for query parameter flightDate. [2020-08-011] is not a valid date. Expected [yyyy-MM-dd]

As a result, we can wrap this message in a nice JSON response coupled with an HTTP 400 response code:

{
  "message": "Invalid value '2020-08-011' for query parameter flightDate. [2020-08-011] is not a valid date. Expected [yyyy-MM-dd]"
}

My request here is to expand this to something like this:

{
  "message": "Invalid value '2020-08-011' for query parameter flightDate. [2020-08-011] is not a valid date. Expected [yyyy-MM-dd]",
  "field": "flightDate",
  "errorValue": "2020-08-011"
}

I guess this can be achieved by passing in the erroneous parameters and metadata when constructing the InvalidQueryParameterException (or any other APIKit validation exceptions).

A workaround to this would be to define regular expressions around APIKit error messages but that's an extremely brittle solution since error messages might change (as they did in APIKit 3.8 --> APIKit 3.9)

Thanks,
Justin

@justinsaliba justinsaliba changed the title More description exception responses Exception Metadata Jul 10, 2020
@justinsaliba justinsaliba changed the title Exception Metadata Validation Exception Metadata Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant