fix status code when container found on unhealthy node

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2016-01-04 17:24:10 -08:00
parent 2982243db6
commit cc7acf92e7
2 changed files with 22 additions and 7 deletions

View File

@ -375,7 +375,7 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
} }
if !container.Engine.IsHealthy() { if !container.Engine.IsHealthy() {
httpError(w, fmt.Sprintf("Container %s running on unhealthy node %s", name, container.Engine.Name), http.StatusNotFound) httpError(w, fmt.Sprintf("Container %s running on unhealthy node %s", name, container.Engine.Name), http.StatusInternalServerError)
return return
} }
@ -848,7 +848,10 @@ func proxyNetworkContainerOperation(c *context, w http.ResponseWriter, r *http.R
func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) { func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) {
name, container, err := getContainerFromVars(c, mux.Vars(r)) name, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil { if err != nil {
if container == nil {
httpError(w, err.Error(), http.StatusNotFound) httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -868,7 +871,10 @@ func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) {
func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) { func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) {
name, container, err := getContainerFromVars(c, mux.Vars(r)) name, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil { if err != nil {
if container == nil {
httpError(w, err.Error(), http.StatusNotFound) httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -998,7 +1004,10 @@ func postCommit(c *context, w http.ResponseWriter, r *http.Request) {
// get container // get container
name, container, err := getContainerFromVars(c, vars) name, container, err := getContainerFromVars(c, vars)
if err != nil { if err != nil {
if container == nil {
httpError(w, err.Error(), http.StatusNotFound) httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return return
} }
// Set the full container ID in the proxied URL path. // Set the full container ID in the proxied URL path.
@ -1074,7 +1083,10 @@ func postBuild(c *context, w http.ResponseWriter, r *http.Request) {
func postRenameContainer(c *context, w http.ResponseWriter, r *http.Request) { func postRenameContainer(c *context, w http.ResponseWriter, r *http.Request) {
_, container, err := getContainerFromVars(c, mux.Vars(r)) _, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil { if err != nil {
if container == nil {
httpError(w, err.Error(), http.StatusNotFound) httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -1097,7 +1109,10 @@ func postRenameContainer(c *context, w http.ResponseWriter, r *http.Request) {
func proxyHijack(c *context, w http.ResponseWriter, r *http.Request) { func proxyHijack(c *context, w http.ResponseWriter, r *http.Request) {
name, container, err := getContainerFromVars(c, mux.Vars(r)) name, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil { if err != nil {
if container == nil {
httpError(w, err.Error(), http.StatusNotFound) httpError(w, err.Error(), http.StatusNotFound)
}
httpError(w, err.Error(), http.StatusInternalServerError)
return return
} }
// Set the full container ID in the proxied URL path. // Set the full container ID in the proxied URL path.

View File

@ -65,7 +65,7 @@ func getContainerFromVars(c *context, vars map[string]string) (string, *cluster.
if name, ok := vars["name"]; ok { if name, ok := vars["name"]; ok {
if container := c.cluster.Container(name); container != nil { if container := c.cluster.Container(name); container != nil {
if !container.Engine.IsHealthy() { if !container.Engine.IsHealthy() {
return name, nil, fmt.Errorf("Container %s running on unhealthy node %s", name, container.Engine.Name) return name, container, fmt.Errorf("Container %s running on unhealthy node %s", name, container.Engine.Name)
} }
return name, container, nil return name, container, nil
} }