From ca1b30db10ee38410d92fa48c9616cc867728979 Mon Sep 17 00:00:00 2001 From: Jonathan Boulle Date: Wed, 29 Oct 2014 19:06:41 -0700 Subject: [PATCH] etcdhttp: return 404 when removing nonexistent member --- Documentation/0.5/other_apis.md | 2 +- etcdserver/etcdhttp/client.go | 3 ++- etcdserver/etcdhttp/client_test.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/0.5/other_apis.md b/Documentation/0.5/other_apis.md index cb1afb4f0..b916931d3 100644 --- a/Documentation/0.5/other_apis.md +++ b/Documentation/0.5/other_apis.md @@ -78,7 +78,7 @@ curl http://10.0.0.10:2379/v2/members -XPOST -H "Content-Type: application/json" ## Delete a member -Remove a member from the cluster. +Remove a member from the cluster. The member ID must be a hex-encoded uint64. Returns empty when successful. Returns a string describing the failure condition when unsuccessful. If the member does not exist in the cluster an HTTP 500(TODO: fix this) will be returned. If the cluster fails to process the request within timeout an HTTP 500 will be returned, though the request may be processed later. diff --git a/etcdserver/etcdhttp/client.go b/etcdserver/etcdhttp/client.go index 53f1c4620..0100fda5c 100644 --- a/etcdserver/etcdhttp/client.go +++ b/etcdserver/etcdhttp/client.go @@ -210,7 +210,7 @@ func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } id, err := types.IDFromString(idStr) if err != nil { - writeError(w, httptypes.NewHTTPError(http.StatusBadRequest, err.Error())) + writeError(w, httptypes.NewHTTPError(http.StatusNotFound, fmt.Sprintf("No such member: %s", idStr))) return } err = h.server.RemoveMember(ctx, uint64(id)) @@ -223,6 +223,7 @@ func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Printf("etcdhttp: error removing node %s: %v", id, err) writeError(w, err) default: + log.Printf("etcdhttp: removed node %x", id) w.WriteHeader(http.StatusNoContent) } } diff --git a/etcdserver/etcdhttp/client_test.go b/etcdserver/etcdhttp/client_test.go index f03846c06..78e0a4e0a 100644 --- a/etcdserver/etcdhttp/client_test.go +++ b/etcdserver/etcdhttp/client_test.go @@ -845,7 +845,7 @@ func TestServeMembersFail(t *testing.T) { }, nil, - http.StatusBadRequest, + http.StatusNotFound, }, { // etcdserver.RemoveMember with no ID