Browse Source

etcdhttp: return 404 when removing nonexistent member

Jonathan Boulle 11 years ago
parent
commit
ca1b30db10

+ 1 - 1
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
 ## 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. 
 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.
 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.

+ 2 - 1
etcdserver/etcdhttp/client.go

@@ -210,7 +210,7 @@ func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		}
 		}
 		id, err := types.IDFromString(idStr)
 		id, err := types.IDFromString(idStr)
 		if err != nil {
 		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
 			return
 		}
 		}
 		err = h.server.RemoveMember(ctx, uint64(id))
 		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)
 			log.Printf("etcdhttp: error removing node %s: %v", id, err)
 			writeError(w, err)
 			writeError(w, err)
 		default:
 		default:
+			log.Printf("etcdhttp: removed node %x", id)
 			w.WriteHeader(http.StatusNoContent)
 			w.WriteHeader(http.StatusNoContent)
 		}
 		}
 	}
 	}

+ 1 - 1
etcdserver/etcdhttp/client_test.go

@@ -845,7 +845,7 @@ func TestServeMembersFail(t *testing.T) {
 			},
 			},
 			nil,
 			nil,
 
 
-			http.StatusBadRequest,
+			http.StatusNotFound,
 		},
 		},
 		{
 		{
 			// etcdserver.RemoveMember with no ID
 			// etcdserver.RemoveMember with no ID