mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-14 06:39:32 +08:00
Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode
This commit is contained in:
commit
8399613018
@ -6,13 +6,9 @@ import (
|
||||
)
|
||||
|
||||
func GinError(c *gin.Context, err error) {
|
||||
if err == nil {
|
||||
GinSuccess(c, nil)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, ParseError(err))
|
||||
}
|
||||
|
||||
func GinSuccess(c *gin.Context, data any) {
|
||||
c.JSON(http.StatusOK, apiSuccess(data))
|
||||
c.JSON(http.StatusOK, ApiSuccess(data))
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ type ApiResponse struct {
|
||||
|
||||
func isAllFieldsPrivate(v any) bool {
|
||||
typeOf := reflect.TypeOf(v)
|
||||
if typeOf == nil {
|
||||
return false
|
||||
}
|
||||
if typeOf.Kind() == reflect.Ptr {
|
||||
typeOf = typeOf.Elem()
|
||||
}
|
||||
@ -30,7 +33,7 @@ func isAllFieldsPrivate(v any) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func apiSuccess(data any) *ApiResponse {
|
||||
func ApiSuccess(data any) *ApiResponse {
|
||||
if isAllFieldsPrivate(data) {
|
||||
return &ApiResponse{}
|
||||
}
|
||||
@ -40,6 +43,9 @@ func apiSuccess(data any) *ApiResponse {
|
||||
}
|
||||
|
||||
func ParseError(err error) *ApiResponse {
|
||||
if err == nil {
|
||||
return ApiSuccess(nil)
|
||||
}
|
||||
unwrap := errs.Unwrap(err)
|
||||
if codeErr, ok := unwrap.(errs.CodeError); ok {
|
||||
resp := ApiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()}
|
||||
|
Loading…
x
Reference in New Issue
Block a user