mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
ctx
This commit is contained in:
parent
05ae254d3d
commit
eba6993726
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GinError(c *gin.Context, err error) {
|
func GinError(c *gin.Context, err error) {
|
||||||
c.JSON(http.StatusOK, ApiError(err))
|
c.JSON(http.StatusOK, ParseError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GinSuccess(c *gin.Context, data any) {
|
func GinSuccess(c *gin.Context, data any) {
|
||||||
|
@ -30,7 +30,7 @@ func isAllFieldsPrivate(v any) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiSuccess(data any) *ApiResponse {
|
func ApiSuccess(data any) *ApiResponse {
|
||||||
if isAllFieldsPrivate(data) {
|
if isAllFieldsPrivate(data) {
|
||||||
return &ApiResponse{}
|
return &ApiResponse{}
|
||||||
}
|
}
|
||||||
@ -40,6 +40,9 @@ func apiSuccess(data any) *ApiResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParseError(err error) *ApiResponse {
|
func ParseError(err error) *ApiResponse {
|
||||||
|
if err == nil {
|
||||||
|
return ApiSuccess(nil)
|
||||||
|
}
|
||||||
unwrap := errs.Unwrap(err)
|
unwrap := errs.Unwrap(err)
|
||||||
if codeErr, ok := unwrap.(errs.CodeError); ok {
|
if codeErr, ok := unwrap.(errs.CodeError); ok {
|
||||||
resp := ApiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()}
|
resp := ApiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user