mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 19:16:35 +08:00
groupCallback
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package call_back_struct
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@@ -26,26 +26,25 @@ type CommonCallbackReq struct {
|
||||
}
|
||||
|
||||
type CallbackResp interface {
|
||||
Parse() (IsPass bool, err error)
|
||||
Parse() (err error)
|
||||
}
|
||||
|
||||
type CommonCallbackResp struct {
|
||||
ActionCode int `json:"actionCode"`
|
||||
ErrCode int `json:"errCode"`
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
func (c *CommonCallbackResp) Parse() (isPass bool, err error) {
|
||||
if c.ActionCode != 0 {
|
||||
err = errors.New(fmt.Sprintf("callback response error actionCode is %d, errCode is %d, errMsg is %s", c.ActionCode, c.ErrCode, c.ErrMsg))
|
||||
return false, err
|
||||
func (c *CommonCallbackResp) Parse() (err error) {
|
||||
if c.ActionCode != constant.NoError || c.ErrCode != constant.NoError {
|
||||
newErr := constant.ErrCallback
|
||||
newErr.ErrCode = c.ErrCode
|
||||
newErr.DetailErrMsg = fmt.Sprintf("callback response error actionCode is %d, errCode is %d, errMsg is %s", c.ActionCode, c.ErrCode, c.ErrMsg)
|
||||
err = newErr
|
||||
return
|
||||
}
|
||||
if c.ErrCode != 0 {
|
||||
err = errors.New(fmt.Sprintf("callback response error actionCode is %d, errCode is %d, errMsg is %s", c.ActionCode, c.ErrCode, c.ErrMsg))
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
return
|
||||
}
|
||||
|
||||
type UserStatusBaseCallback struct {
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
type ErrInfo struct {
|
||||
ErrCode int32
|
||||
ErrMsg string
|
||||
WrapErrMsg string
|
||||
ErrCode int32
|
||||
ErrMsg string
|
||||
DetailErrMsg string
|
||||
}
|
||||
|
||||
func (e ErrInfo) Error() string {
|
||||
@@ -24,13 +24,15 @@ func (e ErrInfo) Code() int32 {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrNone = ErrInfo{0, "", ""}
|
||||
ErrRpcConn = ErrInfo{GRPCConnIsNil, "grpc conn is nil", ""}
|
||||
ErrArgs = ErrInfo{ArgsError, "ArgsError", ""}
|
||||
ErrDatabase = ErrInfo{DatabaseError, "DatabaseError", ""}
|
||||
ErrInternalServer = ErrInfo{ServerInternalError, "ServerInternalError", ""}
|
||||
ErrNetwork = ErrInfo{NetworkError, "NetworkError", ""}
|
||||
ErrNoPermission = ErrInfo{NoPermissionError, "NoPermissionError", ""}
|
||||
ErrNone = ErrInfo{0, "", ""}
|
||||
ErrRpcConn = ErrInfo{GRPCConnIsNil, "grpc conn is nil", ""}
|
||||
ErrArgs = ErrInfo{ArgsError, "ArgsError", ""}
|
||||
ErrDatabase = ErrInfo{DatabaseError, "DatabaseError", ""}
|
||||
ErrInternalServer = ErrInfo{ServerInternalError, "ServerInternalError", ""}
|
||||
ErrNetwork = ErrInfo{NetworkError, "NetworkError", ""}
|
||||
ErrNoPermission = ErrInfo{NoPermissionError, "NoPermissionError", ""}
|
||||
ErrCallback = ErrInfo{ErrMsg: "CallbackError"}
|
||||
ErrCallbackContinue = ErrInfo{ErrMsg: "CallbackContinueError"}
|
||||
|
||||
ErrUserIDNotFound = ErrInfo{UserIDNotFoundError, "UserIDNotFoundError", ""}
|
||||
ErrGroupIDNotFound = ErrInfo{GroupIDNotFoundError, "GroupIDNotFoundError", ""}
|
||||
@@ -62,7 +64,7 @@ var (
|
||||
|
||||
func toDetail(err error, info ErrInfo) ErrInfo {
|
||||
errInfo := info
|
||||
errInfo.WrapErrMsg = err.Error()
|
||||
errInfo.DetailErrMsg = err.Error()
|
||||
return errInfo
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package http
|
||||
|
||||
import (
|
||||
cbApi "Open_IM/pkg/call_back_struct"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
@@ -57,22 +58,22 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func CallBackPostReturn(url, callbackCommand string, input interface{}, output cbApi.CallbackResp, timeOut int, failedContinue *bool) (bool, error) {
|
||||
func CallBackPostReturn(url, callbackCommand string, input interface{}, output cbApi.CallbackResp, timeOut int, failedContinue *bool) error {
|
||||
v := urlLib.Values{}
|
||||
v.Set("callbackCommand", callbackCommand)
|
||||
url = url + "?" + v.Encode()
|
||||
b, err := Post(url, input, timeOut)
|
||||
if err != nil {
|
||||
if failedContinue != nil {
|
||||
return *failedContinue, err
|
||||
if failedContinue != nil && *failedContinue {
|
||||
return constant.ErrCallbackContinue
|
||||
}
|
||||
return true, err
|
||||
return constant.ErrNetwork
|
||||
}
|
||||
if err = json.Unmarshal(b, output); err != nil {
|
||||
if failedContinue != nil {
|
||||
return *failedContinue, err
|
||||
if failedContinue != nil && *failedContinue {
|
||||
return constant.ErrCallbackContinue
|
||||
}
|
||||
return true, err
|
||||
return constant.ErrData
|
||||
}
|
||||
return output.Parse()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user