Fix generated JSON in case of error
This commit is contained in:
parent
ce46313dd1
commit
d03350f6b3
3 changed files with 3 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in a new issue