mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-09-16 16:39:59 +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) {
|
func GinError(c *gin.Context, err error) {
|
||||||
if err == nil {
|
|
||||||
GinSuccess(c, nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.JSON(http.StatusOK, ParseError(err))
|
c.JSON(http.StatusOK, ParseError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GinSuccess(c *gin.Context, data any) {
|
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 {
|
func isAllFieldsPrivate(v any) bool {
|
||||||
typeOf := reflect.TypeOf(v)
|
typeOf := reflect.TypeOf(v)
|
||||||
|
if typeOf == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if typeOf.Kind() == reflect.Ptr {
|
if typeOf.Kind() == reflect.Ptr {
|
||||||
typeOf = typeOf.Elem()
|
typeOf = typeOf.Elem()
|
||||||
}
|
}
|
||||||
@ -30,7 +33,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 +43,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