Update usages of http.ResponseWriter.WriteHeader to use http.Error

Signed-off-by: Ibrahim AshShohail <me@ibrasho.com>
This commit is contained in:
Ibrahim AshShohail
2018-10-08 22:20:52 +03:00
parent add731dff1
commit 2fb3ba71f1
12 changed files with 29 additions and 32 deletions

View File

@@ -120,7 +120,7 @@ func makeTestServer(t *testing.T, namespace string) (*httptest.Server, *utiltest
mux.Handle(testapi.Default.ResourcePath("endpoints/", namespace, ""), &fakeEndpointsHandler)
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
t.Errorf("unexpected request: %v", req.RequestURI)
res.WriteHeader(http.StatusNotFound)
http.Error(res, "", http.StatusNotFound)
})
return httptest.NewServer(mux), &fakeEndpointsHandler
}

View File

@@ -252,7 +252,7 @@ type debugHTTPHandler struct {
func (h *debugHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/graph" {
w.WriteHeader(http.StatusNotFound)
http.Error(w, "", http.StatusNotFound)
return
}
@@ -270,8 +270,7 @@ func (h *debugHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
data, err := dot.Marshal(graph, "full", "", " ", false)
if err != nil {
w.Write([]byte(err.Error()))
w.WriteHeader(http.StatusInternalServerError)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(data)