-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Return remote API errors as JSON #22880
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
0f28216 to
49cbb77
Compare
|
Also see the discussion here; #22104 /cc @justincormack @Silex |
|
I think it's fine, but should probably be part of a big release with big warnings in order to give time to adapt for tools used to the old format. |
|
@Silex yes, there should be a warning in the changelog; of course systems can still pin to an older version of the API |
|
+1 (non-binding), but I have a question: why do you need "code" verbosely in HTTP body, even though it is included in the HTTP header? |
|
@AkihiroSuda It's a fairly common pattern putting the response code in REST API error responses. It's useful in cases where the client doesn't make it easy to get at the response code (e.g. curl) and stuff like that. Agreed though that theoretically it's redundant, but I guess it's just a convenience thing. I don't have strong feelings about this, so happy to remove if others do have strong feelings! |
|
I think I like the error in the response, but wondering if there's a standard JSON response structure for errors; if there is, would be nice to use that. Otherwise, I'm +1 to changing |
|
I don't think we should be conflating errors with wire format. Currently registry uses the errcode package which does indeed marshal the errors to json, but also provides a good way to determine what the error actual is and makes RPC significantly simpler. |
|
Closest thing to a standard: http://jsonapi.org/format/#errors At the very least, we should be returning a JSON response with the message that usually gets returned as a plain text string. That could almost be considered a bug and is causing users problems. We can work our way towards a more sophisticated system with proper codes and multiple errors at some point in the future I suppose. |
|
@bfirsh But who are we breaking by not changing this now? Who will benefit from getting a json object with a message if we do change it now? My biggest concern: |
|
@cpuguy83 the main benefit right now is uniformity, and consistency of always getting json. In future it makes it easier to add additional more structured error info, eg you could get a stack trace in debug mode or file + line number information about where the error came from, and we could wrap the errors from runc and containerd better. |
|
The janky test failure should go away if you rebase |
49cbb77 to
bd9eec0
Compare
|
@cpuguy83 Pretty much what @justincormack said. It's also makes it harder to write clients, and it is impossible to specify with a Swagger API specification. I have updated this PR to use |
|
Some clarification about backwards compatibility: even if users aren't fixing to a particular version of the API, it is unlikely to affect them. If it is being consumed by a bit of code, they are probably using pattern matching to find the error, and the pattern will still be in the response. If it is being consumed by a human, worst case they still see the error with a bit of JSON around it. |
bd9eec0 to
67db6e4
Compare
|
The status code has been removed in the engine-api change, and we're only returning a message for now (we can always add more if needed); docker-archive-public/docker.engine-api#233 I'm moving this to code review; design LGTM |
67db6e4 to
5614b8c
Compare
|
docker-archive-public/docker.engine-api#233 has been merged so properly vendored it now. |
5614b8c to
31b03b4
Compare
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.
That's a nit and not required for the PR (so it's more a quick note). We might want to add a helper for that (checkError(…)) 👼
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.
Agreed. Wasn't sure whether this was a good idea because a lot of other stuff in tests like this is explicit. Also, it might actually be less neat because we probably want a function that gets the message from the error then the assertion to be in the test, which means an extra line to check for errors when unmarshalling. I guess it could also be a go-checker checker.
Aaanyway. I will add a helper in a follow-up PR if I find time. :)
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.
okok I'm just making excuses. Added a getErrorMessage helper. ✨
|
gccgo is 💚. |
|
LGTM |
|
@vdemeester anything on the docs? |
|
Docs LGTM 🐹 |
31b03b4 to
686fbf1
Compare
|
rebased! |
Signed-off-by: Ben Firshman <ben@firshman.co.uk>
686fbf1 to
322e2a7
Compare
|
Fixed some broken tests from the rebase and added |
- What I did
The Remote API returns JSON responses on success and plain text responses on failure. There have been complaints that this is unexpected. It is also impossible to represent this using a Swagger API definition. It has also been mentioned in #5893.
This pull request makes the response body of API errors JSON in the form
{"message": ...}. API versions <1.24 will continue to return plain text errors.It depends upon docker-archive-public/docker.engine-api#233 but this PR is ready to review besides vendoring that.
- How to verify it
- Description for the changelog
Remote API errors are now returned as JSON.
- A picture of a cute animal (not mandatory but encouraged)