Browse code

Merge pull request #12539 from WeiZhang555/httpError

change httpError logic

Jessie Frazelle authored on 2015/04/21 09:26:09
Showing 1 changed files
... ...
@@ -195,6 +195,10 @@ func parseMultipartForm(r *http.Request) error {
195 195
 }
196 196
 
197 197
 func httpError(w http.ResponseWriter, err error) {
198
+	if err == nil || w == nil {
199
+		logrus.WithFields(logrus.Fields{"error": err, "writer": w}).Error("unexpected HTTP error handling")
200
+		return
201
+	}
198 202
 	statusCode := http.StatusInternalServerError
199 203
 	// FIXME: this is brittle and should not be necessary.
200 204
 	// If we need to differentiate between different possible error types, we should
... ...
@@ -214,10 +218,8 @@ func httpError(w http.ResponseWriter, err error) {
214 214
 		statusCode = http.StatusForbidden
215 215
 	}
216 216
 
217
-	if err != nil {
218
-		logrus.Errorf("HTTP Error: statusCode=%d %v", statusCode, err)
219
-		http.Error(w, err.Error(), statusCode)
220
-	}
217
+	logrus.WithFields(logrus.Fields{"statusCode": statusCode, "err": err}).Error("HTTP Error")
218
+	http.Error(w, err.Error(), statusCode)
221 219
 }
222 220
 
223 221
 // writeJSONEnv writes the engine.Env values to the http response stream as a