Browse Source

etcdhttp: always respond json-format error to client

Yicheng Qin 11 years ago
parent
commit
9aefb91531
2 changed files with 4 additions and 3 deletions
  1. 2 2
      etcdserver/etcdhttp/client_test.go
  2. 2 1
      etcdserver/etcdhttp/http.go

+ 2 - 2
etcdserver/etcdhttp/client_test.go

@@ -1124,7 +1124,7 @@ func TestBadServeKeys(t *testing.T) {
 			},
 
 			http.StatusInternalServerError,
-			"Internal Server Error",
+			`{"message":"Internal Server Error"}`,
 		},
 		{
 			// etcdserver.Server etcd error
@@ -1144,7 +1144,7 @@ func TestBadServeKeys(t *testing.T) {
 			},
 
 			http.StatusInternalServerError,
-			"Internal Server Error",
+			`{"message":"Internal Server Error"}`,
 		},
 	}
 	for i, tt := range testBadCases {

+ 2 - 1
etcdserver/etcdhttp/http.go

@@ -51,7 +51,8 @@ func writeError(w http.ResponseWriter, err error) {
 		e.WriteTo(w)
 	default:
 		log.Printf("etcdhttp: unexpected error: %v", err)
-		http.Error(w, "Internal Server Error", http.StatusInternalServerError)
+		herr := httptypes.NewHTTPError(http.StatusInternalServerError, "Internal Server Error")
+		herr.WriteTo(w)
 	}
 }