mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-23 09:50:27 +08:00
error
This commit is contained in:
parent
5ca36ebc10
commit
1513933922
@ -19,6 +19,5 @@ func (t *thirdServer) ConfirmPut(ctx context.Context, req *third.ConfirmPutReq)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *thirdServer) CleanObject(ctx context.Context, now time.Time) {
|
func (t *thirdServer) CleanObject(ctx context.Context, now time.Time) {
|
||||||
//清理过期的对象
|
t.s3dataBase.CleanExpirationObject(ctx, now)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package constant
|
package constant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"OpenIM/pkg/utils"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
@ -29,6 +31,14 @@ func (e *ErrInfo) Code() int32 {
|
|||||||
return e.ErrCode
|
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 {
|
func (e *ErrInfo) Wrap(msg ...string) error {
|
||||||
return errors.Wrap(e, strings.Join(msg, "--"))
|
return errors.Wrap(e, strings.Join(msg, "--"))
|
||||||
}
|
}
|
||||||
@ -48,6 +58,22 @@ func toDetail(err error, info *ErrInfo) *ErrInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ToAPIErrWithErr(err error) *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("")
|
errComm := errors.New("")
|
||||||
var marshalErr *json.MarshalerError
|
var marshalErr *json.MarshalerError
|
||||||
errInfo := &ErrInfo{}
|
errInfo := &ErrInfo{}
|
||||||
|
@ -8,7 +8,7 @@ var (
|
|||||||
ErrNetwork = &ErrInfo{NetworkError, "NetworkError", ""}
|
ErrNetwork = &ErrInfo{NetworkError, "NetworkError", ""}
|
||||||
ErrNoPermission = &ErrInfo{NoPermissionError, "NoPermissionError", ""}
|
ErrNoPermission = &ErrInfo{NoPermissionError, "NoPermissionError", ""}
|
||||||
ErrIdentity = &ErrInfo{IdentityError, "IdentityError", ""}
|
ErrIdentity = &ErrInfo{IdentityError, "IdentityError", ""}
|
||||||
ErrCallback = &ErrInfo{ErrMsg: "CallbackError"}
|
ErrCallback = &ErrInfo{CallbackError, "CallbackError", ""}
|
||||||
ErrCallbackContinue = &ErrInfo{ErrMsg: "CallbackContinueError"}
|
ErrCallbackContinue = &ErrInfo{ErrMsg: "CallbackContinueError"}
|
||||||
|
|
||||||
ErrUserIDNotFound = &ErrInfo{UserIDNotFoundError, "UserIDNotFoundError", ""}
|
ErrUserIDNotFound = &ErrInfo{UserIDNotFoundError, "UserIDNotFoundError", ""}
|
||||||
@ -95,6 +95,8 @@ const (
|
|||||||
IdentityError = 90008 // 身份错误 非管理员token,且token中userID与请求userID不一致
|
IdentityError = 90008 // 身份错误 非管理员token,且token中userID与请求userID不一致
|
||||||
|
|
||||||
ConfigError = 90009
|
ConfigError = 90009
|
||||||
|
|
||||||
|
CallbackError = 80000
|
||||||
)
|
)
|
||||||
|
|
||||||
// 账号错误码
|
// 账号错误码
|
||||||
|
@ -22,6 +22,7 @@ type S3Database interface {
|
|||||||
ApplyPut(ctx context.Context, req *third.ApplyPutReq) (*third.ApplyPutResp, error)
|
ApplyPut(ctx context.Context, req *third.ApplyPutReq) (*third.ApplyPutResp, error)
|
||||||
GetPut(ctx context.Context, req *third.GetPutReq) (*third.GetPutResp, error)
|
GetPut(ctx context.Context, req *third.GetPutReq) (*third.GetPutResp, error)
|
||||||
ConfirmPut(ctx context.Context, req *third.ConfirmPutReq) (*third.ConfirmPutResp, error)
|
ConfirmPut(ctx context.Context, req *third.ConfirmPutReq) (*third.ConfirmPutResp, error)
|
||||||
|
CleanExpirationObject(ctx context.Context, t time.Time)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewS3Database(obj obj.Interface, hash relation.ObjectHashModelInterface, info relation.ObjectInfoModelInterface, put relation.ObjectPutModelInterface) S3Database {
|
func NewS3Database(obj obj.Interface, hash relation.ObjectHashModelInterface, info relation.ObjectInfoModelInterface, put relation.ObjectPutModelInterface) S3Database {
|
||||||
|
103
pkg/errs/code.go
Normal file
103
pkg/errs/code.go
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package errs
|
||||||
|
|
||||||
|
// UnknownCode 没有解析到code或解析的code=0
|
||||||
|
const UnknownCode = 1000
|
||||||
|
|
||||||
|
const (
|
||||||
|
FormattingError = 10001
|
||||||
|
HasRegistered = 10002
|
||||||
|
NotRegistered = 10003
|
||||||
|
PasswordErr = 10004
|
||||||
|
GetIMTokenErr = 10005
|
||||||
|
RepeatSendCode = 10006
|
||||||
|
MailSendCodeErr = 10007
|
||||||
|
SmsSendCodeErr = 10008
|
||||||
|
CodeInvalidOrExpired = 10009
|
||||||
|
RegisterFailed = 10010
|
||||||
|
ResetPasswordFailed = 10011
|
||||||
|
RegisterLimit = 10012
|
||||||
|
LoginLimit = 10013
|
||||||
|
InvitationError = 10014
|
||||||
|
)
|
||||||
|
|
||||||
|
// 通用错误码
|
||||||
|
const (
|
||||||
|
NoError = 0 //无错误
|
||||||
|
ArgsError = 90001 //输入参数错误
|
||||||
|
DatabaseError = 90002 //redis/mysql等db错误
|
||||||
|
ServerInternalError = 90003 //服务器内部错误
|
||||||
|
NetworkError = 90004 //网络错误
|
||||||
|
NoPermissionError = 90005 //权限不足
|
||||||
|
GRPCConnIsNil = 90006 //grpc连接空
|
||||||
|
|
||||||
|
DefaultOtherError = 90006 //其他错误
|
||||||
|
DataError = 90007 //数据错误
|
||||||
|
|
||||||
|
IdentityError = 90008 // 身份错误 非管理员token,且token中userID与请求userID不一致
|
||||||
|
|
||||||
|
ConfigError = 90009
|
||||||
|
|
||||||
|
CallbackError = 80000
|
||||||
|
)
|
||||||
|
|
||||||
|
// 账号错误码
|
||||||
|
const (
|
||||||
|
UserIDNotFoundError = 91001 //UserID不存在 或未注册
|
||||||
|
GroupIDNotFoundError = 91002 //GroupID不存在
|
||||||
|
RecordNotFoundError = 91002 //记录不存在
|
||||||
|
GroupIDIDExisted = 91002 //GroupID已存在
|
||||||
|
UserIDExisted = 91002 //UserID已存在
|
||||||
|
)
|
||||||
|
|
||||||
|
// 关系链错误码
|
||||||
|
const (
|
||||||
|
RelationshipAlreadyError = 92001 //已经是好友关系(或者黑名单)
|
||||||
|
NotRelationshipYetError = 92002 //不是好友关系(或者黑名单)
|
||||||
|
CanNotAddYourselfError = 92003 //不能添加自己为好友
|
||||||
|
BlockedByPeer = 92004 //被对方拉黑
|
||||||
|
NotPeersFriend = 92005 //不是对方的好友
|
||||||
|
)
|
||||||
|
|
||||||
|
// 群组错误码
|
||||||
|
const (
|
||||||
|
OnlyOneOwnerError = 93001 //只能有一个群主
|
||||||
|
InGroupAlreadyError = 93003 //已在群组中
|
||||||
|
NotInGroupYetError = 93004 //不在群组中
|
||||||
|
DismissedAlreadyError = 93004 //群组已经解散
|
||||||
|
OwnerNotAllowedQuitError = 93004 //群主不能退群
|
||||||
|
GroupTypeNotSupport = 93005
|
||||||
|
GroupNoOwner = 93006
|
||||||
|
|
||||||
|
MutedInGroup = 93007 //群成员被禁言
|
||||||
|
MutedGroup = 93008 //群被禁言
|
||||||
|
)
|
||||||
|
|
||||||
|
// 用户错误码
|
||||||
|
const (
|
||||||
|
RegisteredAlreadyError = 94001 //用户已经注册过了
|
||||||
|
)
|
||||||
|
|
||||||
|
// token错误码
|
||||||
|
const (
|
||||||
|
TokenExpiredError = 95001
|
||||||
|
TokenInvalidError = 95002
|
||||||
|
TokenMalformedError = 95003
|
||||||
|
TokenNotValidYetError = 95004
|
||||||
|
TokenUnknownError = 95005
|
||||||
|
TokenKickedError = 95006
|
||||||
|
TokenDifferentPlatformIDError = 95007
|
||||||
|
TokenDifferentUserIDError = 95008
|
||||||
|
TokenNotExistError = 95009
|
||||||
|
)
|
||||||
|
|
||||||
|
// 消息错误码
|
||||||
|
const (
|
||||||
|
MessageHasReadDisable = 96001
|
||||||
|
)
|
||||||
|
|
||||||
|
// 长连接网关错误码
|
||||||
|
const (
|
||||||
|
ConnOverMaxNumLimit = 970001
|
||||||
|
ConnArgsErr = 970002
|
||||||
|
ConnUpdateErr = 970003
|
||||||
|
)
|
@ -7,16 +7,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Code interface {
|
type Coderr interface {
|
||||||
Code() int
|
Code() int
|
||||||
Msg() string
|
Msg() string
|
||||||
}
|
Warp(msg ...string) error
|
||||||
|
|
||||||
type Coderr interface {
|
|
||||||
Code
|
|
||||||
Detail() string
|
|
||||||
WithDetail(string) Coderr
|
|
||||||
Warp(...string) error
|
|
||||||
error
|
error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,15 +27,6 @@ type errInfo struct {
|
|||||||
detail string
|
detail string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *errInfo) WithDetail(s string) Coderr {
|
|
||||||
if e.detail == "" {
|
|
||||||
e.detail = s
|
|
||||||
} else {
|
|
||||||
e.detail = s + ", " + e.detail
|
|
||||||
}
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *errInfo) Code() int {
|
func (e *errInfo) Code() int {
|
||||||
return e.code
|
return e.code
|
||||||
}
|
}
|
||||||
@ -50,10 +35,6 @@ func (e *errInfo) Msg() string {
|
|||||||
return e.msg
|
return e.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *errInfo) Detail() string {
|
|
||||||
return e.detail
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *errInfo) Warp(w ...string) error {
|
func (e *errInfo) Warp(w ...string) error {
|
||||||
return errors.Wrap(e, strings.Join(w, ", "))
|
return errors.Wrap(e, strings.Join(w, ", "))
|
||||||
}
|
}
|
||||||
@ -65,16 +46,3 @@ func (e *errInfo) Error() string {
|
|||||||
func Unwrap(err error) error {
|
func Unwrap(err error) error {
|
||||||
return utils.Unwrap(err)
|
return utils.Unwrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCode(err error) Code {
|
|
||||||
if err == nil {
|
|
||||||
return NewCodeError(UnknownCode, "nil")
|
|
||||||
}
|
|
||||||
if code, ok := Unwrap(err).(Code); ok {
|
|
||||||
if code.Code() == 0 {
|
|
||||||
return NewCodeError(UnknownCode, "code == 0")
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
return NewCodeError(UnknownCode, "unknown code")
|
|
||||||
}
|
|
||||||
|
@ -1,4 +1 @@
|
|||||||
package errs
|
package errs
|
||||||
|
|
||||||
// UnknownCode 没有解析到code或解析的code=0
|
|
||||||
const UnknownCode = 1000
|
|
||||||
|
59
pkg/errs/errors.go
Normal file
59
pkg/errs/errors.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package errs
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrArgs = NewCodeError(ArgsError, "ArgsError")
|
||||||
|
ErrDatabase = NewCodeError(DatabaseError, "DatabaseError")
|
||||||
|
ErrInternalServer = NewCodeError(ServerInternalError, "ServerInternalError")
|
||||||
|
ErrNetwork = NewCodeError(NetworkError, "NetworkError")
|
||||||
|
ErrNoPermission = NewCodeError(NoPermissionError, "NoPermissionError")
|
||||||
|
ErrIdentity = NewCodeError(IdentityError, "IdentityError")
|
||||||
|
ErrCallback = NewCodeError(CallbackError, "CallbackError")
|
||||||
|
|
||||||
|
ErrUserIDNotFound = NewCodeError(UserIDNotFoundError, "UserIDNotFoundError")
|
||||||
|
ErrGroupIDNotFound = NewCodeError(GroupIDNotFoundError, "GroupIDNotFoundError")
|
||||||
|
ErrGroupIDExisted = NewCodeError(GroupIDIDExisted, "GroupIDExisted")
|
||||||
|
ErrUserIDExisted = NewCodeError(UserIDExisted, "UserIDExisted")
|
||||||
|
|
||||||
|
ErrRecordNotFound = NewCodeError(RecordNotFoundError, "RecordNotFoundError")
|
||||||
|
|
||||||
|
ErrRelationshipAlready = NewCodeError(RelationshipAlreadyError, "RelationshipAlreadyError")
|
||||||
|
ErrNotRelationshipYet = NewCodeError(NotRelationshipYetError, "NotRelationshipYetError")
|
||||||
|
ErrCanNotAddYourself = NewCodeError(CanNotAddYourselfError, "CanNotAddYourselfError")
|
||||||
|
|
||||||
|
ErrOnlyOneOwner = NewCodeError(OnlyOneOwnerError, "OnlyOneOwnerError")
|
||||||
|
ErrInGroupAlready = NewCodeError(InGroupAlreadyError, "InGroupAlreadyError")
|
||||||
|
ErrNotInGroupYet = NewCodeError(NotInGroupYetError, "NotInGroupYetError")
|
||||||
|
ErrDismissedAlready = NewCodeError(DismissedAlreadyError, "DismissedAlreadyError")
|
||||||
|
ErrOwnerNotAllowedQuit = NewCodeError(OwnerNotAllowedQuitError, "OwnerNotAllowedQuitError")
|
||||||
|
ErrRegisteredAlready = NewCodeError(RegisteredAlreadyError, "RegisteredAlreadyError")
|
||||||
|
ErrGroupTypeNotSupport = NewCodeError(GroupTypeNotSupport, "")
|
||||||
|
ErrGroupNoOwner = NewCodeError(GroupNoOwner, "ErrGroupNoOwner")
|
||||||
|
|
||||||
|
ErrDefaultOther = NewCodeError(DefaultOtherError, "DefaultOtherError")
|
||||||
|
ErrData = NewCodeError(DataError, "DataError")
|
||||||
|
ErrTokenExpired = NewCodeError(TokenExpiredError, "TokenExpiredError")
|
||||||
|
ErrTokenInvalid = NewCodeError(TokenInvalidError, "TokenInvalidError") //
|
||||||
|
ErrTokenMalformed = NewCodeError(TokenMalformedError, "TokenMalformedError") //格式错误
|
||||||
|
ErrTokenNotValidYet = NewCodeError(TokenNotValidYetError, "TokenNotValidYetError") //还未生效
|
||||||
|
ErrTokenUnknown = NewCodeError(TokenUnknownError, "TokenUnknownError") //未知错误
|
||||||
|
ErrTokenKicked = NewCodeError(TokenKickedError, "TokenKickedError")
|
||||||
|
ErrTokenNotExist = NewCodeError(TokenNotExistError, "TokenNotExistError") //在redis中不存在
|
||||||
|
ErrTokenDifferentPlatformID = NewCodeError(TokenDifferentPlatformIDError, "TokenDifferentPlatformIDError")
|
||||||
|
ErrTokenDifferentUserID = NewCodeError(TokenDifferentUserIDError, "TokenDifferentUserIDError")
|
||||||
|
|
||||||
|
ErrMessageHasReadDisable = NewCodeError(MessageHasReadDisable, "MessageHasReadDisable")
|
||||||
|
|
||||||
|
ErrBlockedByPeer = NewCodeError(BlockedByPeer, "BlockedByPeer")
|
||||||
|
//不是对方的好友
|
||||||
|
ErrNotPeersFriend = NewCodeError(NotPeersFriend, "NotPeersFriend")
|
||||||
|
|
||||||
|
ErrMutedInGroup = NewCodeError(MutedInGroup, "MutedInGroup")
|
||||||
|
ErrMutedGroup = NewCodeError(MutedGroup, "MutedGroup")
|
||||||
|
|
||||||
|
ErrConnOverMaxNumLimit = NewCodeError(ConnOverMaxNumLimit, "ConnOverMaxNumLimit")
|
||||||
|
|
||||||
|
ErrConnArgsErr = NewCodeError(ConnArgsErr, "args err, need token, sendID, platformID")
|
||||||
|
ErrConnUpdateErr = NewCodeError(ConnArgsErr, "upgrade http conn err")
|
||||||
|
|
||||||
|
ErrConfig = NewCodeError(ConfigError, "ConfigError")
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user