Skip to content
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

update status code for network api #30699

Merged

Conversation

allencloud
Copy link
Contributor

@allencloud allencloud commented Feb 3, 2017

Signed-off-by: allencloud allen.sun@daocloud.io

fixes #30698

- What I did

  1. add status code 500 for api endpoint GET /networks/(id or name), status code 500 is from https://github.com/docker/docker/blob/master/daemon/network.go#L61;
  2. add status code 403 for api endpoint DELETE /networks/(id or name), status code is from https://github.com/docker/docker/blob/master/daemon/network.go#L454;
  3. update network api endpoints' url, replace id with id or name.

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@allencloud allencloud changed the title update status code for network api [WIP]update status code for network api Feb 3, 2017
@allencloud allencloud changed the title [WIP]update status code for network api update status code for network api Feb 3, 2017
@allencloud
Copy link
Contributor Author

allencloud commented Feb 3, 2017

CI fails in janky:

07:21:52 =================================== FAILURES ===================================
07:21:52 _______________ ArchiveTest.test_get_file_archive_from_container _______________
07:21:52 /docker-py/tests/integration/container_test.py:498: in test_get_file_archive_from_container
07:21:52     self.client.start(ctnr)
07:21:52 /docker-py/docker/utils/decorators.py:21: in wrapped
07:21:52     return f(self, resource_id, *args, **kwargs)
07:21:52 /docker-py/docker/api/container.py:383: in start
07:21:52     self._raise_for_status(res)
07:21:52 /docker-py/docker/client.py:177: in _raise_for_status
07:21:52     raise errors.APIError(e, response, explanation=explanation)
07:21:52 E   APIError: 500 Server Error: Internal Server Error ("endpoint with name epic_hermann already exists in network bridge")
07:21:52 ============== 1 failed, 118 passed, 3 skipped in 144.46 seconds ===============

I am afraid change I made takes affect in docker-py, but I have no idea what to do in docker-py.
Could you give me some guidance? ping @thaJeztah @vdemeester

@LK4D4
Copy link
Contributor

LK4D4 commented Feb 3, 2017

ping @shin-

@shin-
Copy link
Contributor

shin- commented Feb 3, 2017

Looks like a random naming conflict - try kicking up the build again.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah added this to the 1.13.1 milestone Feb 3, 2017
@thaJeztah
Copy link
Member

verified with docker 1.9 for the older API versions

@justincormack
Copy link
Contributor

The 500 status code is not correct - the request is invalid (multiple IDs match the short ID), not the server having a problem, it should be a 400 error. So we should not document it, we should fix.

I recommend http://racksburg.com/choosing-an-http-status-code/

@allencloud
Copy link
Contributor Author

allencloud commented Feb 4, 2017

Thanks for the double check @thaJeztah

And thanks for your feedback, @justincormack . What you mentioned is reasonable, I think. At first, I think we should fix this without doubt. While maybe this is a two-phase work.

  1. Since the old versions of docker suffer such improper status code of 500 for a long time, and these old versions' code has already frozen. As a result, I think what can do is add this status code of 500 in the old api docs to keep consistency. After all, api docs miss the status code, sometimes it may cause issues for user's experience with daemon's API.

  2. fix this status code 500 to be a more accurate status code 400 in a follow-up PR.

WDYT? @justincormack

@allencloud
Copy link
Contributor Author

I think now pr #30453 added code https://github.com/docker/docker/blob/master/api/server/router/network/network_routes.go#L147 and https://github.com/docker/docker/blob/master/api/server/router/network/network_routes.go#L157 in docker/master. And this pr introduced a kind of error which will be returned a status code of 500.

I think it seems OK for master to add 500. While for the legacy, any input? @justincormack @thaJeztah

@vdemeester vdemeester modified the milestone: 1.13.1 Feb 13, 2017
@thaJeztah thaJeztah modified the milestones: 17.03.0, 1.13.1 Feb 18, 2017
@allencloud allencloud force-pushed the update-status-code-for-network-api branch from c4bf6f8 to 5c304f5 Compare February 20, 2017 03:43
@vieux vieux removed this from the 17.03.0 milestone Feb 20, 2017
@LK4D4
Copy link
Contributor

LK4D4 commented Feb 27, 2017

ping @justincormack @thaJeztah

@allencloud allencloud force-pushed the update-status-code-for-network-api branch 3 times, most recently from f6df244 to af6c99a Compare March 10, 2017 02:40
@allencloud
Copy link
Contributor Author

ping @justincormack @thaJeztah
Sorry for bothering you again. And I sincerely wish we could make this move on. This pr maybe could help something in improving the docs about status code.

Yeah, I totally agree on that 401 is better for multi networks matching.

While for the old versions of Docker, they still lack the more precise status code 403 and 500 for GET /networks/{id} doc.

In master, I think there some places which return 500 now, like:

        if err := httputils.ParseForm(r); err != nil {
		return err
	}

and

return fmt.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName))

So, adding a 500 seems OK, but for 401 bad request, I think we need a follow-up. We should consider more about that, because POST /networks/{id or nam}/connect and POST /networks/{id or name}/disconnect should also be taken into consideration. WDYT?

@allencloud allencloud force-pushed the update-status-code-for-network-api branch from af6c99a to a98046e Compare March 17, 2017 05:25
@LK4D4
Copy link
Contributor

LK4D4 commented Mar 20, 2017

ping @thaJeztah @justincormack

@allencloud allencloud force-pushed the update-status-code-for-network-api branch from a98046e to 439c677 Compare March 31, 2017 05:49
@allencloud
Copy link
Contributor Author

Could we move on this pr currently, my friends? Any feedback helps. 😃

@allencloud allencloud force-pushed the update-status-code-for-network-api branch from 439c677 to 235c404 Compare April 10, 2017 09:34
Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: allencloud <allen.sun@daocloud.io>
@allencloud
Copy link
Contributor Author

Seems, z and powerpc, there is always one who is naughty to pick errors 😄

@vdemeester vdemeester merged commit 72f4fc7 into moby:master Apr 15, 2017
@allencloud allencloud deleted the update-status-code-for-network-api branch April 16, 2017 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DOC] network api docs seem to miss some status codes
10 participants