gf
gf copied to clipboard
Question: I wanna change http response Code in `gcode` , What is the best way for me to do it ?
1. What version of Go
and system type/arch are you using?
go version go1.16.2 windows/amd64
2. What version of GoFrame
are you using?
github.com/gogf/gf/v2 v2.0.0-rc3
3. Can this issue be re-produced with the latest release?
yes
4. What did you do?
I wanna change http response Code in my way . I found the http Code in goframe errors\gcode\gcode.go
var (
CodeNil = localCode{-1, "", nil} // No error code specified.
CodeOK = localCode{0, "OK", nil} // It is OK.
CodeInternalError = localCode{50, "Internal Error", nil} // An error occurred internally.
CodeValidationFailed = localCode{51, "Validation Failed", nil} // Data validation failed.
........
CodeBusinessValidationFailed = localCode{300, "Business Validation Failed", nil} // Business validation failed.
)
I wanna change CodeValidationFailed = localCode{51, "Validation Failed", nil}
into CodeValidationFailed = localCode{400, "Validation Failed and xxxxxxx", nil}
.
What is the best way for me to do it ?
P.S.
I also implment the MiddlewareHandlerResponse
in group.Middleware()
and Code
Struct in my own way just like gcode
.
But Finally I found CodeValidationFailed
used in gvalid
which I really want the gvalid
functions and abilities .
I also want to know
@zhonghuaxunGM You can change the error code in middleware. The internal error code can be retrieved using gerror.Code(r.GetError())
, you can use switch ... case ...
mechanism to do the change.