func ResponseHandler(r *ghttp.Request) {
r.Middleware.Next()
// There's custom buffer content, it then exits current handler.
if r.Response.BufferLength() > 0 {
return
}
res, err := r.GetHandlerResponse()
code := gerror.Code(err)
if code == gcode.CodeNil && err != nil {
code = gcode.CodeInternalError
}
if detail, ok := code.Detail().(BizCode); ok {
g.Log().Errorf(r.Context(), `error caused by user "%+v"`, detail.User)
}
_ = r.Response.WriteJson(ghttp.DefaultHandlerResponse{
Code: gcode.CodeOK.Code(),
Message: gcode.CodeOK.Message(),
Data: res,
})
}