Code

Don't return an HTTP error status if a handler fails.
authorSebastian Harl <sh@tokkee.org>
Wed, 26 Nov 2014 21:10:00 +0000 (22:10 +0100)
committerSebastian Harl <sh@tokkee.org>
Wed, 26 Nov 2014 21:10:00 +0000 (22:10 +0100)
This might confuse browsers and, more importantly, now we re-populate the
query input field with the user's query in case it failed.

server/server.go

index 6b3f8d07a57e5ae715fb828df75cb1f4c556332c..c0f449cd451dd8d735107c8d8ca877f6fa5aabbc 100644 (file)
@@ -182,19 +182,22 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
                return
        }
        r.ParseForm()
-       page, err := f(req, s)
+       p, err := f(req, s)
        if err != nil {
-               s.badrequest(w, fmt.Errorf("Error: %v", err))
-               return
+               p = &page{
+                       Content: "<section class=\"error\">" +
+                               html(fmt.Sprintf("Error: %v", err)) +
+                               "</section>",
+               }
        }
 
-       page.Query = r.FormValue("query")
-       if page.Title == "" {
-               page.Title = "SysDB - The System Database"
+       p.Query = r.FormValue("query")
+       if p.Title == "" {
+               p.Title = "SysDB - The System Database"
        }
 
        var buf bytes.Buffer
-       err = s.main.Execute(&buf, page)
+       err = s.main.Execute(&buf, p)
        if err != nil {
                s.internal(w, err)
                return