mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 01:55:58 +08:00
ws update
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ func GinError(c *gin.Context, err error) {
|
||||
GinSuccess(c, nil)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, apiError(err))
|
||||
c.JSON(http.StatusOK, ParseError(err))
|
||||
}
|
||||
|
||||
func GinSuccess(c *gin.Context, data any) {
|
||||
|
||||
+7
-7
@@ -5,7 +5,7 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type apiResponse struct {
|
||||
type ApiResponse struct {
|
||||
ErrCode int `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
ErrDlt string `json:"errDlt"`
|
||||
@@ -30,23 +30,23 @@ func isAllFieldsPrivate(v any) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func apiSuccess(data any) *apiResponse {
|
||||
func apiSuccess(data any) *ApiResponse {
|
||||
if isAllFieldsPrivate(data) {
|
||||
return &apiResponse{}
|
||||
return &ApiResponse{}
|
||||
}
|
||||
return &apiResponse{
|
||||
return &ApiResponse{
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func apiError(err error) *apiResponse {
|
||||
func ParseError(err error) *ApiResponse {
|
||||
unwrap := errs.Unwrap(err)
|
||||
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()}
|
||||
if resp.ErrDlt == "" {
|
||||
resp.ErrDlt = err.Error()
|
||||
}
|
||||
return &resp
|
||||
}
|
||||
return &apiResponse{ErrCode: errs.ServerInternalError, ErrMsg: err.Error()}
|
||||
return &ApiResponse{ErrCode: errs.ServerInternalError, ErrMsg: err.Error()}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user