auto creating error with code in ghttp.MiddlewareHandlerResponse when there's no 200 http status code
@@ -40,7 +40,8 @@ func MiddlewareHandlerResponse(r *Request) {
code = gcode.CodeInternalError
}
msg = err.Error()
- } else if r.Response.Status > 0 && r.Response.Status != http.StatusOK {
+ } else {
+ if r.Response.Status > 0 && r.Response.Status != http.StatusOK {
msg = http.StatusText(r.Response.Status)
switch r.Response.Status {
case http.StatusNotFound:
@@ -50,9 +51,14 @@ func MiddlewareHandlerResponse(r *Request) {
default:
code = gcode.CodeUnknown
}
+ // It creates error as it can be retrieved by other middlewares.
+ err = gerror.NewCode(code, msg)
+ r.SetError(err)
} else {
code = gcode.CodeOK
}
+ }
+
r.Response.WriteJson(DefaultHandlerResponse{
Code: code.Code(),
Message: msg,
