Browse code

Fix error string mapping to HTTP response code to ignore case

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)

Phil Estes authored on 2014/10/24 02:34:06
Showing 1 changed files
... ...
@@ -92,17 +92,18 @@ func httpError(w http.ResponseWriter, err error) {
92 92
 	// FIXME: this is brittle and should not be necessary.
93 93
 	// If we need to differentiate between different possible error types, we should
94 94
 	// create appropriate error types with clearly defined meaning.
95
-	if strings.Contains(err.Error(), "no such") {
95
+	errStr := strings.ToLower(err.Error())
96
+	if strings.Contains(errStr, "no such") {
96 97
 		statusCode = http.StatusNotFound
97
-	} else if strings.Contains(err.Error(), "Bad parameter") {
98
+	} else if strings.Contains(errStr, "bad parameter") {
98 99
 		statusCode = http.StatusBadRequest
99
-	} else if strings.Contains(err.Error(), "Conflict") {
100
+	} else if strings.Contains(errStr, "conflict") {
100 101
 		statusCode = http.StatusConflict
101
-	} else if strings.Contains(err.Error(), "Impossible") {
102
+	} else if strings.Contains(errStr, "impossible") {
102 103
 		statusCode = http.StatusNotAcceptable
103
-	} else if strings.Contains(err.Error(), "Wrong login/password") {
104
+	} else if strings.Contains(errStr, "wrong login/password") {
104 105
 		statusCode = http.StatusUnauthorized
105
-	} else if strings.Contains(err.Error(), "hasn't been activated") {
106
+	} else if strings.Contains(errStr, "hasn't been activated") {
106 107
 		statusCode = http.StatusForbidden
107 108
 	}
108 109
 
... ...
@@ -1050,7 +1051,7 @@ func postContainersCopy(eng *engine.Engine, version version.Version, w http.Resp
1050 1050
 	w.Header().Set("Content-Type", "application/x-tar")
1051 1051
 	if err := job.Run(); err != nil {
1052 1052
 		log.Errorf("%s", err.Error())
1053
-		if strings.Contains(err.Error(), "No such container") {
1053
+		if strings.Contains(strings.ToLower(err.Error()), "no such container") {
1054 1054
 			w.WriteHeader(http.StatusNotFound)
1055 1055
 		} else if strings.Contains(err.Error(), "no such file or directory") {
1056 1056
 			return fmt.Errorf("Could not find the file %s in container %s", origResource, vars["name"])