Browse Source

Merge pull request #1631 from xiangli-cmu/validate_doc

Validate doc
Xiang Li 11 years ago
parent
commit
b53a98eb38

+ 1 - 1
Documentation/0.5/other_apis.md

@@ -51,7 +51,7 @@ curl http://10.0.0.10:2379/v2/members
 
 
 Returns an HTTP 201 response code and the representation of added member with a newly generated a memberID when successful. Returns a string describing the failure condition when unsuccessful. 
 Returns an HTTP 201 response code and the representation of added member with a newly generated a memberID when successful. Returns a string describing the failure condition when unsuccessful. 
 
 
-If the POST body is malformed an HTTP 400 will be returned. If the member exists in the cluster or existed in the cluster at some point in the past 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 POST body is malformed an HTTP 400 will be returned. If the member exists in the cluster or existed in the cluster at some point in the past an HTTP 409 will be returned. If any of the given peerURLs exists in the cluster an HTTP 409 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.
 
 
 ### Request
 ### Request
 
 

+ 1 - 1
etcdserver/etcdhttp/client.go

@@ -189,7 +189,7 @@ func (h *membersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		err = h.server.AddMember(ctx, *m)
 		err = h.server.AddMember(ctx, *m)
 		switch {
 		switch {
 		case err == etcdserver.ErrIDExists || err == etcdserver.ErrPeerURLexists:
 		case err == etcdserver.ErrIDExists || err == etcdserver.ErrPeerURLexists:
-			writeError(w, httptypes.NewHTTPError(http.StatusPreconditionFailed, err.Error()))
+			writeError(w, httptypes.NewHTTPError(http.StatusConflict, err.Error()))
 			return
 			return
 		case err != nil:
 		case err != nil:
 			log.Printf("etcdhttp: error adding node %s: %v", m.ID, err)
 			log.Printf("etcdhttp: error adding node %s: %v", m.ID, err)

+ 28 - 0
etcdserver/etcdhttp/client_test.go

@@ -773,6 +773,34 @@ func TestServeMembersFail(t *testing.T) {
 
 
 			http.StatusInternalServerError,
 			http.StatusInternalServerError,
 		},
 		},
+		{
+			// etcdserver.AddMember error
+			&http.Request{
+				URL:    mustNewURL(t, membersPrefix),
+				Method: "POST",
+				Body:   ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)),
+				Header: map[string][]string{"Content-Type": []string{"application/json"}},
+			},
+			&errServer{
+				etcdserver.ErrIDExists,
+			},
+
+			http.StatusConflict,
+		},
+		{
+			// etcdserver.AddMember error
+			&http.Request{
+				URL:    mustNewURL(t, membersPrefix),
+				Method: "POST",
+				Body:   ioutil.NopCloser(strings.NewReader(`{"PeerURLs": ["http://127.0.0.1:1"]}`)),
+				Header: map[string][]string{"Content-Type": []string{"application/json"}},
+			},
+			&errServer{
+				etcdserver.ErrPeerURLexists,
+			},
+
+			http.StatusConflict,
+		},
 		{
 		{
 			// etcdserver.RemoveMember error with arbitrary server error
 			// etcdserver.RemoveMember error with arbitrary server error
 			&http.Request{
 			&http.Request{