-
Notifications
You must be signed in to change notification settings - Fork 114
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
Non-standard JSON API error objects used #231
Comments
The type of For validation errors, the best detail we can provide is the result of the Joi validation library, to aid engineers when building and consuming API's. If we change this behaviour, it needs to produce a message that is helpful for all variations of validation failure - something I'm not confident in doing. I'm in no rush to change this behaviour. There's an implication that we're not 100% to-spec, however it's a trade-off that makes this project easier to work with and consume. |
As a programmer, I like the extra detail provided by Joi's validation library. I created this issue because I am writing a client using the spec as a reference and it failed to parse the errors detail values returned by It may be worthwhile contacting the spec authors and asking for clarification on the error In my case, I've updated my client to work with error objects returned by this library and string values, but I wouldn't expect other JSON API clients to necessarily do the same based on the spec. This will likely cause incompatibilies around error handling with other libraries. |
The type that detail is intended to be may be loosely implied by the specification, but any ambiguity is cleared up in the schema. If this library is not validating its responses with that schema, then you might want to consider it: it can be really helpful to make sure things like this don't slip through the cracks! The solution to the particular example in this issue is straightforward, I think: map each validation error to its own JSON API error. The "description" of that error should be the "message" from Joi. Then, the rest of the content of the Joi error can live happily in In other words: errors: [{
"status": "403",
"code": "EFORBIDDEN",
"title": "Param validation failed",
"detail": "\"FIELD\" is not allowed to be empty",
"meta": {
"path": "FIELD",
"type": "any.empty",
"context": {
"key": "FIELD"
}
}
}] This does lead to more data being sent over the wire, but it's:
|
I am confused because in my experience with the sample app provided in this repo, not even the regular response I get is jsonapi-compliant. I don't get the objects with the For instance, I get something like this:
When if I expect jsonapi, I would expect something like this:
Am I missing something here? |
When an error is returned it is sent similar to the following:
The JSON API Error spec says the
detail
key should be a human-readable string but the server is returning an array of objects.The text was updated successfully, but these errors were encountered: