From fac451ad60c950cf5906ebc3bf8ee197e992ce18 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 23 Nov 2014 16:02:07 +0100 Subject: [PATCH] Improved error reporting in graph(): correctly report bad requests. --- server/error.go | 4 ++++ server/graph.go | 2 +- server/server.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/error.go b/server/error.go index 49fec43..2afa44a 100644 --- a/server/error.go +++ b/server/error.go @@ -40,6 +40,10 @@ func (s *Server) notfound(w http.ResponseWriter, r *http.Request) { s.err(w, http.StatusNotFound, fmt.Errorf("%s not found", r.RequestURI)) } +func (s *Server) badrequest(w http.ResponseWriter, err error) { + s.err(w, http.StatusBadRequest, err) +} + func (s *Server) internal(w http.ResponseWriter, err error) { s.err(w, http.StatusInternalServerError, err) } diff --git a/server/graph.go b/server/graph.go index 9406f76..941e51d 100644 --- a/server/graph.go +++ b/server/graph.go @@ -46,7 +46,7 @@ import ( func (s *Server) graph(w http.ResponseWriter, req request) { if len(req.args) != 2 { - s.internal(w, fmt.Errorf("Missing host/metric information")) + s.badrequest(w, fmt.Errorf("Missing host/metric information")) } host := proto.EscapeString(req.args[0]) diff --git a/server/server.go b/server/server.go index 309cdb6..6b3f8d0 100644 --- a/server/server.go +++ b/server/server.go @@ -151,7 +151,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { for _, f := range strings.Split(path, "/") { f, err := url.QueryUnescape(f) if err != nil { - s.err(w, http.StatusBadRequest, fmt.Errorf("Error: %v", err)) + s.badrequest(w, fmt.Errorf("Error: %v", err)) return } fields = append(fields, f) @@ -184,7 +184,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { r.ParseForm() page, err := f(req, s) if err != nil { - s.err(w, http.StatusBadRequest, fmt.Errorf("Error: %v", err)) + s.badrequest(w, fmt.Errorf("Error: %v", err)) return } -- 2.30.2