Browse Source

change httpError logic

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Signed-off-by: Zhang Wei <zhangwei198900@gmail.com>
Zhang Wei 10 years ago
parent
commit
66239ab5c9
1 changed files with 6 additions and 4 deletions
  1. 6 4
      api/server/server.go

+ 6 - 4
api/server/server.go

@@ -130,6 +130,10 @@ func parseMultipartForm(r *http.Request) error {
 }
 }
 
 
 func httpError(w http.ResponseWriter, err error) {
 func httpError(w http.ResponseWriter, err error) {
+	if err == nil || w == nil {
+		logrus.WithFields(logrus.Fields{"error": err, "writer": w}).Error("unexpected HTTP error handling")
+		return
+	}
 	statusCode := http.StatusInternalServerError
 	statusCode := http.StatusInternalServerError
 	// FIXME: this is brittle and should not be necessary.
 	// FIXME: this is brittle and should not be necessary.
 	// If we need to differentiate between different possible error types, we should
 	// If we need to differentiate between different possible error types, we should
@@ -149,10 +153,8 @@ func httpError(w http.ResponseWriter, err error) {
 		statusCode = http.StatusForbidden
 		statusCode = http.StatusForbidden
 	}
 	}
 
 
-	if err != nil {
-		logrus.Errorf("HTTP Error: statusCode=%d %v", statusCode, err)
-		http.Error(w, err.Error(), statusCode)
-	}
+	logrus.WithFields(logrus.Fields{"statusCode": statusCode, "err": err}).Error("HTTP Error")
+	http.Error(w, err.Error(), statusCode)
 }
 }
 
 
 // writeJSONEnv writes the engine.Env values to the http response stream as a
 // writeJSONEnv writes the engine.Env values to the http response stream as a