-
Notifications
You must be signed in to change notification settings - Fork 890
Add error examples #281
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
Add error examples #281
Conversation
Questions:
|
|
||
{ | ||
"errors": [{ | ||
"title": "The title field must not be empty", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense of this to be in the detail
? I wasn't sure if
It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization
applied on the field or resource level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since path
links to a single field ("title"), i think the title should be about that specific field.
I understand detail
as a long form of title
. So another example could be… a Dog resource where a name field must be one of the Disney characters but the user tried to set it to "steve" (not in that list) instead . Now title
could say something rather generic like "The dog must be named after a Disney character" whereas detail
would render a very long error description like "Lorem ipsum Disney […] Goofy, Pluto, Mini Mouse, please […]". Or am i on the wrong track here?
In the JSON API implementation for Django REST Framework that I'm working on, we are just using I do have another related question though: How should errors across multiple fields (or not field related) be represented? Currently we are using I wouldn't mind seeing examples for authentication errors as well, we are serializing them currently like {
"errors": [{
"status": "403",
"title": "Authentication credentials were not provided."
}]
} |
For what it's worth my current errors look like this: {
"errors": [
{ "id": "email_not_unique" },
{ "id": "password_too_small" }
]
} I use the |
I have experienced quite a bit of unhappiness with the current errors definition. I want to identify a scope to which one or more problems apply. The scope could be at a resource level or field level. Json-api has links and a path and this just doesnt seem to fit. It doesn't allow multiple problems to be specified once you have identified the problem area. I am not sure why we don't just have a json pointer (what json patch uses) to identify the problem scope and allow a collection of problems. Each problem can then have a title, detail and additional information such as code, reason or anything else the server wishes to return. IMO errors could just be: {
"errors": [
{ "path": "<json pointer>",
"problems": [{
"title": "Some text",
"detail": "Detailed explanation",
"code": "some_code",
"whatever": " you need"
}, {
// etc
}
]
}
]
} An alternative format is to drop the errors array and return an object using the distinct json pointers as the keys: {
"errors": {
"<json pointer>": [{
"title": "Some text",
"detail": "Detailed explanation",
"code": "some_code",
"whatever": " you need"
}, {
// etc
}],
"<json pointer>": [
// etc
]
}
} |
This was brought up in the original errors conversation, but decided against. |
@krainboltgreene Thanks. Any reference where it was discussed and more importantly why? I am aware a draft nottingham rfc was looked at, and I looked at it too and it looks like an il conceived spec given its intent. I believe it had some influence on the json -API error designbut was ultimately diverged since the draft rfc had little hope of meeting json-api requirements. Does anyone have a set of use cases or requirements for json-api? It seems there is an unspoken set of requirements and very little rationale for how things are. Given this I don't see why we cannot change anything in the interests of pragmatism. Json API allows multiple resources to be specified in all create and update actions so errors need to provide adressability of problems balanced with unnecessary repetition. The spec needs trimming down to a firm set of capabilities that all implementations must adhere to. Forcing a json pointer provides a definitive scope for problems, anything else is just flimsy design and ultimately the slippery slope to non interoperability. |
Sorry about the delay here! We are certainly interested in adding examples, but this does not merge any more. Are you interested in keeping up this PR? If so, let's go over them in detail, but I'm not going to review until I hear from you 😄 |
@steveklabnik i have updated the example. Using a Rails' i18n-ish looking "code" in the example ("errors.attributes.title.blank"), because there were some questions regarding i18n in the past and I think this is how I would use the field, even without using Rails. |
I have rebased this PR. 👍 👎 ✋ ? |
@ahx I don't think there is a need for a long error code like that if the |
@ColtonProvias I've used the long code ("errors.attributes.title.blank") to resemble a code that you can throw against some i18n library. But this probably is just distracting. So i changed it to "field_empty". |
Sorry for the slow/no response @ahx. If you'd be willing to rebase this one more time and ensure it lines up with 1.0 of the spec, we can get it landed. |
Please rebase/resubmit this PR if you'd like for it to be merged. |
Also, any examples should target the new examples page. |
The errors section needs some examples for clarification. I did not really understand
path
andlinks
until reading #234 (comment)This PR adds a basic example for an error response. I am omitting
id
andcode
anddetail
, because the main purpose was to make clear howpath
can be used.I would appreciate if someone else could add another example where a
links
attribute makes sense like trying to update multiple resources at once where one fails or so.