Report errors

This commit is contained in:
nemunaire 2016-01-18 18:25:32 +01:00
parent c8d1575ee1
commit a6a152166e
1 changed files with 2 additions and 1 deletions

View File

@ -76,6 +76,7 @@ func (a apiRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
ret = map[string]string{"errmsg": err.Error()}
resStatus = http.StatusBadRequest
log.Println(r.RemoteAddr, resStatus, err.Error())
}
if ret == nil {
@ -87,7 +88,7 @@ func (a apiRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(resStatus)
io.WriteString(w, str)
} 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)