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
Introduce error elements. #208
Conversation
Closes #7.
|
@steveklabnik What if multiple fields have errors, e.g. phone and email were invalid. I would encourage you to make the key |
|
As this is lifted almost directly from |
|
@devinus why null? just omit the key entirely. |
|
I believe this is only a top level error, and doesn't account for "validation errors". Is that correct? |
|
@locks I misspoke, I had updated it already. |
|
I lifted it from CJ to give us a straw man to discuss, @stevenharman. I always try to START with what others have done, and evolve from there. @mamund, can you address why this isn't a collection? Do you regret that decision? |
|
@tpitale yes, it s a top-level error. That doesn't mean it couldn't account for certain kinds of internal errors, though. |
|
|
||
| ## Errors | ||
|
|
||
| The error object contains addiitional information on the latest error condition |
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.
typo addiitional
|
I fixed the typo, thanks. |
|
Say there is a thing that aggregates data from different places and i get |
| } | ||
| ``` | ||
|
|
||
| Implementors **MAY** choose to not use this optional feature and use another media type for errors if they so choose. vnd.error and HTTP Problem are two examples. |
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.
I think we probably want to specify a header that implementors can use to indicate an alternate media type for errors:
JSONAPI-Error-Type: application/vnd.error+json
This kind of thing is probably how, in general, we can support extensibility when we chose an existing media type as a default that makes sense to swap out. Obviously, swapping something out will break compatibility with API browsers and clients not explicitly designed to support the alternate, but it will at least make existing clients know to ignore the data instead of trying to interpret it as the default.
|
I'm also in favor of using an array for errors. It's a mess to munge multiple errors into one and a bigger mess to extract them into something meaningful on the client. |
|
Also in favor of using array for errors. I would prefer to not have form validation errors (as an example) to be mashed into one single error. |
|
I agree. Are there any specifications that looks like Rails' format ( |
|
I'd like to throw out a use case: I use nested objects in my API (not nested entities with identity, but nested compound objects) and the error representation is similarly nested. Rails' errors object doesn't support nested errors, but I hope nesting would be considered in a mini-spec as well. Here is an example of a request and the associated error response from the app: https://gist.github.com/samwgoldman/9592722 If we are targeting Rails' error format, don't forget that Rails has it's own nested error handling that uses dot-separated keys in the errors object. I found this unsuitable for my own project, but I suspect many people use this feature. |
|
@samwgoldman good points. I don't think I necessarily want to target Rails' exact format. It may, however, be useful to have MIME types for each variant so that servers can be explicit and client libraries don't have to guess. |
|
@wycats Flexibilty with different MIME types is ideal sounding but I could see that creating a pretty good amount of discussion about all different types that all of us want added. It seems like the format with the most flexibilty would be... {
"errors" : [
{
// Could look like anything
},
{
// Could look like anything
},
{
// Could look like anything
}
]
}where the only change would be "errors" is a reserved key holding an array of resources. |
|
I think we should go with a single, well-specified error object (perhaps derived from Rails, perhaps extended), and then explicitly support extensibility via MIME types. The point of extensibility is to allow people to try out other things without needing them to be blessed right away. |
|
Some thoughts from previous discussion at #7:
|
|
There's a spec being worked on for errors: http://tools.ietf.org/html/draft-nottingham-http-problem-06 Fully extended: {
"type": "https://developer.example.com/errors#invalid_params",
"title": "Validation Failed",
"detail": "Title is missing",
"code_type": "invalid_params",
"instance": "https://api.example.com/requests/REQUEST_ID",
"errors": [{
"type": "https://developer.example.com/errors#missing_field?path=/title&resource=payments",
"title": "Title is missing",
"detail": "Title must be a string longer than 5 characters",
"code_type": "missing_field",
"path": "/title"
}]
} |
|
HTTP-problem was explicitly discussed in #7. |
|
Totally missed this.. ignore:) |
|
Some things to consider about the structure of an error object:
|
|
@krainboltgreene, I would expect some of those issues to be solved with mechanisms other than just error messages returned in the
As those are keys, they'd not be
Not sure I follow what you're talking about here. If the request were for a collection, it would make sense for error messages to either be about the collection, or some how identify the problematic members. Maybe a concrete example would allow for more precise discussion here?
Similar to above - not sure I follow. Perhaps a concrete example?
AMS doesn't tie you to just database columns; you can serialize nearly anything you wish as a value under a key.
Per your example, I would expect such a request to result in either a
That sounds like a |
I don't think you understand: Keys tell the client what value to look up in their i18n dictionary.
My point still stands, it's an error that is tangentially related to the original request.
No, you misunderstand. Sometimes intermediaries change user input and the client needs to know exactly what the server tried to process. Example: User submits a file object, which goes to a file uploading api, which gets turned into a URL, which gets submitted to the server. The server got a URL, which was somehow invalid, and that has to go to the client who can display why (Size problems, file type, etc). |
I think @krainboltgreene means that if the users of the client application speak French but the API server returns "end user friendly" error messages in English, then the messages aren't really appropriate? Maybe there should be some clarification as to who these messages are aimed at. |
|
For strings delivered by the API which are intended for the user directly, the Accept-Language mechanism can be used. |
|
I recently had a twitter convo about this: https://twitter.com/stephencelis/status/460809826616889344 |
|
In my JSON API's I implement errors within a The In my scheme the error key refers to an object and not an array, instead each key of the error object represents a respective key in the object whilst the actual error value is an array of objects to support multiple errors, with each error object having arbitrary error data, reason codes, descriptions etc. I reserve the Example: {
"posts": [{
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Welcome",
"src": "http://example.com/images/mustaches.png",
"_meta": {
"error": {
"_object": [{
"code": "limit_reached",
"desc": "Take a break and come back tomorrow."
}], "title": [{
"code": "reserved",
"extra": "whatever as required..."
}], "src": [{
"code": "license_violation",
"desc": "Copyrighted material"
}, {
"code": "too_big",
"max": "1Mb"
}]
}
}
}]
}I would be interested to get feedback/opinions on the approach I use above. I think it is imperative that JSON-API supports arbitary error information being returned in a structured fashion and straight-forward/easy processing on both client and server. If it doesn't deliver the goods on error handling I doubt it can ever be useful for my applications. |
|
I should also add that
I believe the draft will have difficulty gaining acceptance because it presumes to codify an error handling approach for API's in isolation to the various JSON API styles that exist. There are a myriad of ways of defining a JSON API and error handling needs to be a core part of that particular API style and in line with the way that API approach handles meta information including schema description. Using URIs for problem types is rubbish when an API has documented schema and/or includes schema references. The draft needs to do this because it needs global types as it switches media types away from your API into its own world. Bad idea IMO. Its just my 2c but I think json-api would do well to ignore |
|
This has been superceded by #234, please go check it out. |
Closes #7.
This was taken basically wholesale from Collection+JSON
/cc @wycats