mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 04:25:59 +08:00
error
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
@@ -29,6 +31,14 @@ func (e *ErrInfo) Code() int32 {
|
||||
return e.ErrCode
|
||||
}
|
||||
|
||||
func (e *ErrInfo) Msg() string {
|
||||
return e.ErrMsg
|
||||
}
|
||||
|
||||
func (e *ErrInfo) Detail() string {
|
||||
return e.DetailErrMsg
|
||||
}
|
||||
|
||||
func (e *ErrInfo) Wrap(msg ...string) error {
|
||||
return errors.Wrap(e, strings.Join(msg, "--"))
|
||||
}
|
||||
@@ -48,6 +58,22 @@ func toDetail(err error, info *ErrInfo) *ErrInfo {
|
||||
}
|
||||
|
||||
func ToAPIErrWithErr(err error) *ErrInfo {
|
||||
unwrap := utils.Unwrap(err)
|
||||
if unwrap == gorm.ErrRecordNotFound {
|
||||
return &ErrInfo{
|
||||
ErrCode: ErrRecordNotFound.Code(),
|
||||
ErrMsg: ErrRecordNotFound.Msg(),
|
||||
DetailErrMsg: fmt.Sprintf("%+v", err),
|
||||
}
|
||||
}
|
||||
if errInfo, ok := unwrap.(*ErrInfo); ok {
|
||||
return &ErrInfo{
|
||||
ErrCode: errInfo.Code(),
|
||||
ErrMsg: errInfo.Msg(),
|
||||
DetailErrMsg: fmt.Sprintf("%+v", err),
|
||||
}
|
||||
}
|
||||
|
||||
errComm := errors.New("")
|
||||
var marshalErr *json.MarshalerError
|
||||
errInfo := &ErrInfo{}
|
||||
|
||||
@@ -8,7 +8,7 @@ var (
|
||||
ErrNetwork = &ErrInfo{NetworkError, "NetworkError", ""}
|
||||
ErrNoPermission = &ErrInfo{NoPermissionError, "NoPermissionError", ""}
|
||||
ErrIdentity = &ErrInfo{IdentityError, "IdentityError", ""}
|
||||
ErrCallback = &ErrInfo{ErrMsg: "CallbackError"}
|
||||
ErrCallback = &ErrInfo{CallbackError, "CallbackError", ""}
|
||||
ErrCallbackContinue = &ErrInfo{ErrMsg: "CallbackContinueError"}
|
||||
|
||||
ErrUserIDNotFound = &ErrInfo{UserIDNotFoundError, "UserIDNotFoundError", ""}
|
||||
@@ -95,6 +95,8 @@ const (
|
||||
IdentityError = 90008 // 身份错误 非管理员token,且token中userID与请求userID不一致
|
||||
|
||||
ConfigError = 90009
|
||||
|
||||
CallbackError = 80000
|
||||
)
|
||||
|
||||
// 账号错误码
|
||||
|
||||
Reference in New Issue
Block a user