From a8c19788a3d074e42e7725d653a5d04e9378f003 Mon Sep 17 00:00:00 2001 From: Philip O Toole Date: Tue, 23 Feb 2016 22:36:27 -0500 Subject: [PATCH] Tighten up HTTP error responses --- http/service.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/http/service.go b/http/service.go index be1a5447..99e08509 100644 --- a/http/service.go +++ b/http/service.go @@ -160,7 +160,7 @@ func (s *Service) handleStoreStats(w http.ResponseWriter, r *http.Request) { func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request) { isTx, err := isTx(r) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -179,7 +179,7 @@ func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request) { results, err := s.store.Execute(queries, isTx) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -190,11 +190,11 @@ func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request) { b, err = json.Marshal(results) } if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) // Internal error actually + http.Error(w, err.Error(), http.StatusInternalServerError) } else { _, err = w.Write([]byte(b)) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) } } } @@ -203,7 +203,7 @@ func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request) { func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) { isTx, err := isTx(r) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -231,7 +231,7 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) { rows, err := s.store.Query(queries, isTx) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -243,11 +243,11 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) { b, err = json.Marshal(rows) } if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) // Internal error actually + http.Error(w, err.Error(), http.StatusInternalServerError) } else { _, err = w.Write([]byte(b)) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) } } }