Code

Improved error reporting in graph(): correctly report bad requests.
authorSebastian Harl <sh@tokkee.org>
Sun, 23 Nov 2014 15:02:07 +0000 (16:02 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 23 Nov 2014 15:02:07 +0000 (16:02 +0100)
server/error.go
server/graph.go
server/server.go

index 49fec434712585a015cbf0058500dee05649cf35..2afa44ab98e570c5d43c9aa08508599e0a986bea 100644 (file)
@@ -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)
 }
index 9406f760158029519ecf32edb07f7993c6dfc632..941e51de6b8a994b65111c26181178e7cc2258c4 100644 (file)
@@ -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])
index 309cdb6b35f86541dc528b6f6df742cf30d51f39..6b3f8d07a57e5ae715fb828df75cb1f4c556332c 100644 (file)
@@ -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
        }