-
Notifications
You must be signed in to change notification settings - Fork 890
Example Error Objects #828
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
Conversation
c83632b
to
d985b6d
Compare
{ | ||
"errors": [ | ||
{ | ||
"source": { "pointer": "data/attributes/first_name" }, |
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.
Although underscores are compliant, I'd prefer to use dasherized names, such as first-name
, in examples as per our recommendations.
Thanks for this! Good examples are so crucial to getting a spec adopted. |
"detail": "is too short" | ||
}, | ||
{ | ||
"status": "422", |
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.
Having status
in isolation seems a bit odd. In this example, I'd expect it to be part of the first error object.
I think an example that shows multiple different errors with different status
values would be great. For example, one error object could be a 404
and another 422
, and the status for the whole response could be 400
.
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.
Great, thanks! I made it this way on purpose since I didn't understand when error objects might have different status attributes.
Agreed! Great start here, @bf4 👍 |
I've made some updates, there might be some code blindness going on here.. I'm not sure if I did 'parameter' right. It appears to have evolved from 'path'. I'm also thinking about adding examples of an error object with
And a response with, in addition to an
|
@dgeb @steveklabnik Any more feedback on the changes? (I've made them in incremental commits) |
{ | ||
"errors": [ | ||
{ | ||
"id": "ds.errors.invalid-error-expects-json-api-format", |
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.
This looks more like a code
than an id
:
id: a unique identifier for this particular occurrence of the problem.
code: an application-specific error code, expressed as a string value.
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.
Oh, looks like I somehow mixed up code and id here and in the error codes section as well
FWIW, I got it from https://github.com/emberjs/data/blob/d842890357840700f0ee17f152415be0cba16030/packages/ember-data/lib/adapters/errors.js#L82
Ember.deprecate('`InvalidError` expects json-api formatted errors.', false, { id: 'ds.errors.invalid-error-expects-json-api-format', until: '2.0.0' });
which I misread as an errors object
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.
Updated
``` | ||
|
||
```http | ||
HTTP/1.1 404 Not Found |
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.
Should be 400
, since errors include 404
and 403
statuses.
"source": { "pointer": "data/relationships/author" }, | ||
"detail": "Post author cannot be blank." | ||
} | ||
] |
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.
@dgeb updated and rebased and added a few more source examples. What would a meta example be in an error object (not top-level member meta)? |
New and improved ✨ |
{ | ||
"title": "Adapter Error", | ||
"code": "ds.errors.invalid-error-expects-json-api-format", | ||
"detail": "The adapter rejected the commit because it was invalid" |
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.
Can you make the detail message here a bit more distinct than the title
than it is now?
Also, can you add status
to one of the earlier examples, in addition to having it on the one below? I don't want to imply through the examples that status
is only applicable in cases where there are multiple errors returned at once. It can be useful too when the code processing the JSON isn't directly aware of the HTTP response (and could be useful also if JSON API is eventually used over non-HTTP protocols).
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.
Sure. FWIW, I got that example title/code/detail off of the ember-data project :).
}, | ||
{ | ||
"code": "225", | ||
"source": { "pointer": "data/attributes/password" }, |
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.
Ditto
Merge commit amended and force-pushed. |
} | ||
``` | ||
|
||
It uses `source` to point to the top-level of the document (`"/"`). |
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.
This line needs to say ""
instead of the old "/"
.
Also, I think my comment about why "/"
is inappropriate got accidentally merged into the response. It doesn't make sense there, though, because my example document with {"": "some value"}
is missing, and because a server isn't allowed to respond with comments in its JSON. If you want to explain why ""
is used rather than "/"
, please do it in this paragraph instead.
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.
you a copy editor or I'm just tired of re-reading this ? :)
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.
Maybe both :)
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.
Added an incremental commit to address this to aid in future reviewing. I'll rebase into the merge commit once we're happy.
👍 |
fixing merge conflict... hold on |
Clean up error object examples
rebased |
@ethanresnick LGTM? |
LGTM. Merged. |
Another small complement to json-api#863, to accommodate the table in json-api#828
omg omg 🎆 🌈 ❗ 💥 👯 ❤️ 😍 😃 💯 |
🎉 🎉 🎉 🎉 🎉 |
Really pleased to see this merged. We've needed some error examples for months. @bf4 thanks for all your work here! 💯 @ethanresnick thanks for finishing the review! 🎉 |
Another small complement to json-api#863, to accommodate the table in json-api#828
Per discussion with @dgeb in rails-api/active_model_serializers#1004
References: