Bladeren bron

fix status code and error detection

Victor Vieux 12 jaren geleden
bovenliggende
commit
0862183c86
3 gewijzigde bestanden met toevoegingen van 26 en 24 verwijderingen
  1. 9 7
      api.go
  2. 1 2
      commands.go
  3. 16 15
      docs/sources/remote-api/api.rst

+ 9 - 7
api.go

@@ -75,7 +75,7 @@ func postAuth(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, erro
 		}
 		return b, nil
 	}
-	w.WriteHeader(http.StatusOK)
+	w.WriteHeader(http.StatusNoContent)
 	return nil, nil
 }
 
@@ -94,7 +94,7 @@ func postContainersKill(srv *Server, w http.ResponseWriter, r *http.Request) ([]
 	if err := srv.ContainerKill(name); err != nil {
 		return nil, err
 	}
-	w.WriteHeader(http.StatusOK)
+	w.WriteHeader(http.StatusNoContent)
 	return nil, nil
 }
 
@@ -245,6 +245,7 @@ func postCommit(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, er
 	if err != nil {
 		return nil, err
 	}
+	w.WriteHeader(http.StatusCreated)
 	return b, nil
 }
 
@@ -372,6 +373,7 @@ func postContainers(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte
 	if err != nil {
 		return nil, err
 	}
+	w.WriteHeader(http.StatusCreated)
 	return b, nil
 }
 
@@ -388,7 +390,7 @@ func postContainersRestart(srv *Server, w http.ResponseWriter, r *http.Request)
 	if err := srv.ContainerRestart(name, t); err != nil {
 		return nil, err
 	}
-	w.WriteHeader(http.StatusOK)
+	w.WriteHeader(http.StatusNoContent)
 	return nil, nil
 }
 
@@ -403,7 +405,7 @@ func deleteContainers(srv *Server, w http.ResponseWriter, r *http.Request) ([]by
 	if err := srv.ContainerDestroy(name, v); err != nil {
 		return nil, err
 	}
-	w.WriteHeader(http.StatusOK)
+	w.WriteHeader(http.StatusNoContent)
 	return nil, nil
 }
 
@@ -413,7 +415,7 @@ func deleteImages(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte,
 	if err := srv.ImageDelete(name); err != nil {
 		return nil, err
 	}
-	w.WriteHeader(http.StatusOK)
+	w.WriteHeader(http.StatusNoContent)
 	return nil, nil
 }
 
@@ -423,7 +425,7 @@ func postContainersStart(srv *Server, w http.ResponseWriter, r *http.Request) ([
 	if err := srv.ContainerStart(name); err != nil {
 		return nil, err
 	}
-	w.WriteHeader(http.StatusOK)
+	w.WriteHeader(http.StatusNoContent)
 	return nil, nil
 }
 
@@ -441,7 +443,7 @@ func postContainersStop(srv *Server, w http.ResponseWriter, r *http.Request) ([]
 	if err := srv.ContainerStop(name, t); err != nil {
 		return nil, err
 	}
-	w.WriteHeader(http.StatusOK)
+	w.WriteHeader(http.StatusNoContent)
 	return nil, nil
 }
 

+ 1 - 2
commands.go

@@ -1172,11 +1172,10 @@ func call(method, path string, data interface{}) ([]byte, int, error) {
 	if err != nil {
 		return nil, -1, err
 	}
-	if resp.StatusCode != 200 {
+	if resp.StatusCode < 200 || resp.StatusCode >= 400 {
 		return nil, resp.StatusCode, fmt.Errorf("error: %s", body)
 	}
 	return body, resp.StatusCode, nil
-
 }
 
 func hijack(method, path string, setRawTerminal bool) error {

+ 16 - 15
docs/sources/remote-api/api.rst

@@ -118,7 +118,7 @@ Create a container
 
 	.. sourcecode:: http
 
-	   HTTP/1.1 200 OK
+	   HTTP/1.1 201 OK
 	   
 	   {
 		"Id":"e90e34656806"
@@ -126,7 +126,7 @@ Create a container
 	   }
 	
 	:jsonparam config: the container's configuration
-	:statuscode 200: no error
+	:statuscode 201: no error
 	:statuscode 404: no such container
 	:statuscode 500: server error
 
@@ -312,10 +312,10 @@ Stop a contaier
 
 	.. sourcecode:: http
 
-	   HTTP/1.1 200 OK
+	   HTTP/1.1 204 OK
 	   	
 	:query t: number of seconds to wait before killing the container
-	:statuscode 200: no error
+	:statuscode 204: no error
 	:statuscode 404: no such container
 	:statuscode 500: server error
 
@@ -337,10 +337,10 @@ Restart a container
 
 	.. sourcecode:: http
 
-	   HTTP/1.1 200 OK
+	   HTTP/1.1 204 OK
 	   	
 	:query t: number of seconds to wait before killing the container
-	:statuscode 200: no error
+	:statuscode 204: no error
 	:statuscode 404: no such container
 	:statuscode 500: server error
 
@@ -362,9 +362,9 @@ Kill a container
 
 	.. sourcecode:: http
 
-	   HTTP/1.1 200 OK
+	   HTTP/1.1 204 OK
 	   	
-	:statuscode 200: no error
+	:statuscode 204: no error
 	:statuscode 404: no such container
 	:statuscode 500: server error
 
@@ -445,10 +445,10 @@ Remove a container
 
         .. sourcecode:: http
 
-	   HTTP/1.1 200 OK
+	   HTTP/1.1 204 OK
 
 	:query v: 1 or 0, Remove the volumes associated to the container. Default 0
-        :statuscode 200: no error
+        :statuscode 204: no error
         :statuscode 404: no such container
         :statuscode 500: server error
 
@@ -714,9 +714,9 @@ Remove an image
 
         .. sourcecode:: http
 
-           HTTP/1.1 200 OK
+           HTTP/1.1 204 OK
 
-	:statuscode 200: no error
+	:statuscode 204: no error
         :statuscode 404: no such image
         :statuscode 500: server error
 
@@ -847,6 +847,7 @@ Set auth configuration
            HTTP/1.1 200 OK
 
         :statuscode 200: no error
+        :statuscode 204: no error
         :statuscode 500: server error
 
 
@@ -930,10 +931,10 @@ Create a new image from a container's changes
 
         .. sourcecode:: http
 
-           HTTP/1.1 200 OK
+           HTTP/1.1 201 OK
 	   Content-Type: application/vnd.docker.raw-stream
 
-           {{ STREAM }}
+           {"Id":"596069db4bf5"}
 
 	:query container: source container
 	:query repo: repository
@@ -941,7 +942,7 @@ Create a new image from a container's changes
 	:query m: commit message
 	:query author: author (eg. "John Hannibal Smith <hannibal@a-team.com>")
 	:query run: config automatically applied when the image is run. (ex: {"Cmd": ["cat", "/world"], "PortSpecs":["22"]})
-        :statuscode 200: no error
+        :statuscode 201: no error
 	:statuscode 404: no such container
         :statuscode 500: server error