Double header writes are being performed
Closed this issue · 0 comments
whoisjeremylam commented
CheckAndParseJsonCTX is responsible for writing any errors back to the client. Therefore this block of code writes a second error:
m, err := CheckAndParseJsonCTX(c, w, r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
returnCode := enulib.ReturnCode{RequestId: c.Value(consts.RequestIdKey).(string), Code: -3, Description: err.Error()}
if err := json.NewEncoder(w).Encode(returnCode); err != nil {
panic(err)
}
// ReturnServerError(c, w, err)
return nil
}
It should be replaced by:
m, err := CheckAndParseJsonCTX(c, w, r)
if err != nil {
// Status errors are handled inside CheckAndParseJsonCTX, so we just exit gracefully
return nil
}