Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Conversation

@bfirsh
Copy link
Contributor

@bfirsh bfirsh commented May 21, 2016

@bfirsh bfirsh changed the title Handle errors in JSON from the server Handle JSON errors from the server May 21, 2016
@bfirsh bfirsh force-pushed the handle-json-errors branch from ec14b70 to 78dbbce Compare May 21, 2016 12:27
@cpuguy83
Copy link
Contributor

Hmm, I'm not sure about this.
I like how the registry is handling this with errcode, however I don't think I see much usefulness out of json errors with an HTTP status code and a message.

@calavera
Copy link
Contributor

This is also importing packages from docker/docker, which goes against the practices in this repository.

@bfirsh
Copy link
Contributor Author

bfirsh commented May 23, 2016

@cpuguy83 There is a need for JSON errors of some kind, no strong feelings about whether there's a code or not. Some discussion of that in moby/moby#22880

@calavera Ah, understood. I'll put the error struct in here.

@bfirsh bfirsh force-pushed the handle-json-errors branch from 78dbbce to aab2dfe Compare May 25, 2016 18:03
@bfirsh
Copy link
Contributor Author

bfirsh commented May 25, 2016

Added ErrorResponse instead of using jsonmessage.APIError from docker/docker.

return serverResp, fmt.Errorf("Error response from daemon: %s", bytes.TrimSpace(body))

var errorMessage string
if strings.Contains(resp.Header.Get("Content-Type"), "application/json") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be ==? what are the possible content types? we should check specifically for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server returns application/json; charset=utf-8, and the default is utf-8 so we should support just application/json too.

Realistically we'll only consume/produce utf-8, so perhaps this should check for the exact strings application/json or application/json; charset=utf-8.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Seems like I'm wrong and the Engine actually just returns application/json. Not sure where I found charset=utf-8. Perhaps it was in some documentation somewhere.

I've updated to just check for the exact string application/json.

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
@calavera
Copy link
Contributor

LGTM

@justincormack
Copy link

Tested this and it seems to behave as I would expect with different API versions.

LGTM

(I would prefer to add the error code, but the whole idea is this is extensible later eg we can add stack traces in debug mode or line the error is from, or nested error info from runc etc later so lets go with this now).

@thaJeztah
Copy link
Contributor

moving this to code review; or were we there already?

@justincormack
Copy link

Yes, code LGTM.

@thaJeztah
Copy link
Contributor

LGTM

@thaJeztah thaJeztah merged commit 1ebb0db into docker-archive-public:master Jun 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants