Report errors
This commit is contained in:
parent
c8d1575ee1
commit
a6a152166e
1 changed files with 2 additions and 1 deletions
|
@ -76,6 +76,7 @@ func (a apiRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ret = map[string]string{"errmsg": err.Error()}
|
ret = map[string]string{"errmsg": err.Error()}
|
||||||
resStatus = http.StatusBadRequest
|
resStatus = http.StatusBadRequest
|
||||||
|
log.Println(r.RemoteAddr, resStatus, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if ret == nil {
|
if ret == nil {
|
||||||
|
@ -87,7 +88,7 @@ func (a apiRouting) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(resStatus)
|
w.WriteHeader(resStatus)
|
||||||
io.WriteString(w, str)
|
io.WriteString(w, str)
|
||||||
} else if j, err := json.Marshal(ret); err != nil {
|
} 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 {
|
} else {
|
||||||
w.WriteHeader(resStatus)
|
w.WriteHeader(resStatus)
|
||||||
w.Write(j)
|
w.Write(j)
|
||||||
|
|
Reference in a new issue