From e6c2568f6b3136e47581cd355ebc175fd73275ce Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 3 Jul 2023 21:15:52 +0800 Subject: [PATCH 1/2] refactor: errcode update --- internal/rpc/msg/send.go | 2 +- internal/rpc/user/user.go | 3 ++- pkg/errs/code.go | 46 +++++++++++++++------------------------ pkg/errs/predefine.go | 40 ++++++++++++---------------------- 4 files changed, 35 insertions(+), 56 deletions(-) diff --git a/internal/rpc/msg/send.go b/internal/rpc/msg/send.go index a7fc6533b..b953c27f9 100644 --- a/internal/rpc/msg/send.go +++ b/internal/rpc/msg/send.go @@ -133,7 +133,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbMsg.SendMsgReq } if !isSend { promePkg.Inc(promePkg.SingleChatMsgProcessFailedCounter) - return nil, errs.ErrUserNotRecvMsg + return nil, nil } else { if err = callbackBeforeSendSingleMsg(ctx, req); err != nil { return nil, err diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 15af7a96a..4619db4ce 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -2,6 +2,7 @@ package user import ( "context" + "errors" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "strings" "time" @@ -47,7 +48,7 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error { } users := make([]*tablerelation.UserModel, 0) if len(config.Config.Manager.UserID) != len(config.Config.Manager.Nickname) { - return errs.ErrConfig.Wrap("len(config.Config.Manager.AppManagerUid) != len(config.Config.Manager.Nickname)") + return errors.New("len(config.Config.Manager.AppManagerUid) != len(config.Config.Manager.Nickname)") } for k, v := range config.Config.Manager.UserID { users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.Config.Manager.Nickname[k]}) diff --git a/pkg/errs/code.go b/pkg/errs/code.go index 03abaaff1..736ea6a62 100644 --- a/pkg/errs/code.go +++ b/pkg/errs/code.go @@ -26,7 +26,7 @@ const ( DatabaseError = 90002 //redis/mysql等db错误 NetworkError = 90004 //网络错误 DataError = 90007 //数据错误 - ConfigError = 90009 + CallbackError = 80000 //通用错误码 @@ -38,51 +38,41 @@ const ( // 账号错误码 UserIDNotFoundError = 1101 //UserID不存在 或未注册 - UserIDExisted = 1102 //UserID已存在 - RegisteredAlreadyError = 1103 //用户已经注册过了 + RegisteredAlreadyError = 1102 //用户已经注册过了 // 群组错误码 - GroupIDNotFoundError = 1201 //GroupID不存在 - GroupIDExisted = 1202 //GroupID已存在 - OnlyOneOwnerError = 1203 //只能有一个群主 - InGroupAlreadyError = 1204 //已在群组中 - NotInGroupYetError = 1205 //不在群组中 - DismissedAlreadyError = 1206 //群组已经解散 - OwnerNotAllowedQuitError = 1207 //群主不能退群 - GroupTypeNotSupport = 1208 - GroupNoOwner = 1209 - GroupRequestHandled = 1210 + GroupIDNotFoundError = 1201 //GroupID不存在 + GroupIDExisted = 1202 //GroupID已存在 + NotInGroupYetError = 1203 //不在群组中 + DismissedAlreadyError = 1204 //群组已经解散 + GroupTypeNotSupport = 1205 + GroupRequestHandled = 1206 // 关系链错误码 CanNotAddYourselfError = 1301 //不能添加自己为好友 BlockedByPeer = 1302 //被对方拉黑 NotPeersFriend = 1303 //不是对方的好友 - RelationshipAlreadyError = 1304 //已经是好友关系(或者黑名单) + RelationshipAlreadyError = 1304 //已经是好友关系 // 消息错误码 MessageHasReadDisable = 1401 MutedInGroup = 1402 //群成员被禁言 MutedGroup = 1403 //群被禁言 - UserNotRecvMsg = 1404 //用户设置了不接收消息 - MsgAlreadyRevoke = 1405 //消息已撤回 + MsgAlreadyRevoke = 1404 //消息已撤回 // token错误码 - TokenExpiredError = 1501 - TokenInvalidError = 1502 - TokenMalformedError = 1503 - TokenNotValidYetError = 1504 - TokenUnknownError = 1505 - TokenKickedError = 1506 - TokenDifferentPlatformIDError = 1507 - TokenDifferentUserIDError = 1508 - TokenNotExistError = 1509 + TokenExpiredError = 1501 + TokenInvalidError = 1502 + TokenMalformedError = 1503 + TokenNotValidYetError = 1504 + TokenUnknownError = 1505 + TokenKickedError = 1506 + TokenNotExistError = 1507 // 长连接网关错误码 ConnOverMaxNumLimit = 1601 ConnArgsErr = 1602 - ConnUpdateErr = 1603 // S3错误码 - FileUploadedCompleteError = 1701 // 文件已上传 - FileUploadedExpiredError = 1702 // 上传过期 + FileUploadedExpiredError = 1701 // 上传过期 ) diff --git a/pkg/errs/predefine.go b/pkg/errs/predefine.go index 51a9eeef7..7f4efc913 100644 --- a/pkg/errs/predefine.go +++ b/pkg/errs/predefine.go @@ -12,51 +12,39 @@ var ( ErrUserIDNotFound = NewCodeError(UserIDNotFoundError, "UserIDNotFoundError") ErrGroupIDNotFound = NewCodeError(GroupIDNotFoundError, "GroupIDNotFoundError") ErrGroupIDExisted = NewCodeError(GroupIDExisted, "GroupIDExisted") - ErrUserIDExisted = NewCodeError(UserIDExisted, "UserIDExisted") ErrRecordNotFound = NewCodeError(RecordNotFoundError, "RecordNotFoundError") - 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") - - 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") - ErrDuplicateKey = NewCodeError(DuplicateKeyError, "DuplicateKeyError") + ErrGroupRequestHandled = NewCodeError(GroupRequestHandled, "GroupRequestHandled") + + 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中不存在 + ErrDuplicateKey = NewCodeError(DuplicateKeyError, "DuplicateKeyError") ErrMessageHasReadDisable = NewCodeError(MessageHasReadDisable, "MessageHasReadDisable") - ErrRelationshipAlready = NewCodeError(RelationshipAlreadyError, "RelationshipAlreadyError") ErrCanNotAddYourself = NewCodeError(CanNotAddYourselfError, "CanNotAddYourselfError") ErrBlockedByPeer = NewCodeError(BlockedByPeer, "BlockedByPeer") ErrNotPeersFriend = NewCodeError(NotPeersFriend, "NotPeersFriend") + ErrRelationshipAlready = NewCodeError(RelationshipAlreadyError, "RelationshipAlreadyError") ErrMutedInGroup = NewCodeError(MutedInGroup, "MutedInGroup") ErrMutedGroup = NewCodeError(MutedGroup, "MutedGroup") - ErrUserNotRecvMsg = NewCodeError(UserNotRecvMsg, "UserNotRecvMsg") ErrMsgAlreadyRevoke = NewCodeError(MsgAlreadyRevoke, "MsgAlreadyRevoke") ErrConnOverMaxNumLimit = NewCodeError(ConnOverMaxNumLimit, "ConnOverMaxNumLimit") - ErrConnArgsErr = NewCodeError(ConnArgsErr, "args err, need token, sendID, platformID") - ErrConnUpdateErr = NewCodeError(ConnArgsErr, "upgrade http conn err") - - ErrConfig = NewCodeError(ConfigError, "ConfigError") + ErrConnArgsErr = NewCodeError(ConnArgsErr, "args err, need token, sendID, platformID") - ErrFileUploadedComplete = NewCodeError(FileUploadedCompleteError, "FileUploadedComplete") - ErrFileUploadedExpired = NewCodeError(FileUploadedExpiredError, "FileUploadedExpiredError") - ErrGroupRequestHandled = NewCodeError(GroupRequestHandled, "GroupRequestHandled") + ErrFileUploadedExpired = NewCodeError(FileUploadedExpiredError, "FileUploadedExpiredError") ) From 92f64ddf7c5c13c86582154b4a361053559886e5 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 3 Jul 2023 21:30:22 +0800 Subject: [PATCH 2/2] feat: conn update token --- internal/msggateway/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index fa72297b8..77677b2b6 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -53,6 +53,7 @@ type Client struct { longConnServer LongConnServer closed bool closedErr error + token string } func newClient(ctx *UserConnContext, conn LongConn, isCompress bool) *Client { @@ -65,7 +66,7 @@ func newClient(ctx *UserConnContext, conn LongConn, isCompress bool) *Client { ctx: ctx, } } -func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isBackground, isCompress bool, longConnServer LongConnServer) { +func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isBackground, isCompress bool, longConnServer LongConnServer, token string) { c.w = new(sync.Mutex) c.conn = conn c.PlatformID = utils.StringToInt(ctx.GetPlatformID()) @@ -77,6 +78,7 @@ func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isBackground, c.IsBackground = false c.closed = false c.closedErr = nil + c.token = token } func (c *Client) pongHandler(_ string) error { c.conn.SetReadDeadline(pongWait)