From d03350f6b3dea7ee42abc443568a1b8daf8dc173 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Thu, 26 Oct 2017 14:14:54 +0200 Subject: [PATCH] Fix generated JSON in case of error --- admin/api/handlers.go | 2 +- admin/time.go | 2 +- frontend/time/time.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/admin/api/handlers.go b/admin/api/handlers.go index c0e02bd8..21ee559e 100644 --- a/admin/api/handlers.go +++ b/admin/api/handlers.go @@ -67,7 +67,7 @@ func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, htt w.WriteHeader(resStatus) w.Write(bts) } else if j, err := json.Marshal(ret); err != nil { - http.Error(w, fmt.Sprintf("{\"errmsg\":\"%q\"}", err), http.StatusInternalServerError) + http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError) } else { w.WriteHeader(resStatus) w.Write(j) diff --git a/admin/time.go b/admin/time.go index 4acc2476..29042e7d 100644 --- a/admin/time.go +++ b/admin/time.go @@ -15,7 +15,7 @@ import ( func init() { api.Router().GET("/time.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { if config, err := settings.ReadSettings(path.Join(api.TeamsDir, settings.SettingsFile)); err != nil { - http.Error(w, fmt.Sprintf("{\"errmsg\":\"%q\"}", err), http.StatusInternalServerError) + http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError) } else { time.ChallengeStart = config.Start time.ChallengeEnd = config.End diff --git a/frontend/time/time.go b/frontend/time/time.go index 42db8dc2..a044eea2 100644 --- a/frontend/time/time.go +++ b/frontend/time/time.go @@ -25,7 +25,7 @@ func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") if j, err := json.Marshal(timeObject{ChallengeStart.Unix(), time.Now().Unix(), int(ChallengeEnd.Sub(ChallengeStart).Seconds())}); err != nil { - http.Error(w, fmt.Sprintf("{\"errmsg\":\"%q\"}", err), http.StatusInternalServerError) + http.Error(w, fmt.Sprintf("{\"errmsg\":%q}", err), http.StatusInternalServerError) } else { w.WriteHeader(http.StatusOK) w.Write(j)