From 839af18f49dbe246cce753190829cbb3cae80339 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 1 Feb 2023 11:15:39 +0800 Subject: [PATCH] Error code standardization --- internal/rpc/friend/callback.go | 25 +++++++++-------- internal/rpc/friend/friend.go | 12 ++++---- internal/rpc/msg/friend_notification.go | 37 +++++++++++++------------ pkg/proto/sdk_ws/ws.proto | 20 +++++-------- 4 files changed, 46 insertions(+), 48 deletions(-) diff --git a/internal/rpc/friend/callback.go b/internal/rpc/friend/callback.go index 4204cc0a0..983a5da54 100644 --- a/internal/rpc/friend/callback.go +++ b/internal/rpc/friend/callback.go @@ -6,14 +6,17 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/http" "Open_IM/pkg/common/log" + "Open_IM/pkg/common/tracelog" pbFriend "Open_IM/pkg/proto/friend" + "context" + //"Open_IM/pkg/proto/msg" "Open_IM/pkg/utils" http2 "net/http" ) -func callbackBeforeAddFriendV1(req *pbFriend.AddFriendReq) error { - resp := callbackBeforeAddFriend(req) +func callbackBeforeAddFriendV1(ctx context.Context, req *pbFriend.AddFriendReq) error { + resp := callbackBeforeAddFriend(ctx, req) if resp.ErrCode != 0 { return (&constant.ErrInfo{ ErrCode: resp.ErrCode, @@ -23,28 +26,28 @@ func callbackBeforeAddFriendV1(req *pbFriend.AddFriendReq) error { return nil } -func callbackBeforeAddFriend(req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp { - callbackResp := cbApi.CommonCallbackResp{OperationID: req.CommID.OperationID} +func callbackBeforeAddFriend(ctx context.Context, req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp { + callbackResp := cbApi.CommonCallbackResp{OperationID: tracelog.GetOperationID(ctx)} if !config.Config.Callback.CallbackBeforeAddFriend.Enable { return callbackResp } - log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), req.String()) + commonCallbackReq := &cbApi.CallbackBeforeAddFriendReq{ CallbackCommand: constant.CallbackBeforeAddFriendCommand, - FromUserID: req.CommID.FromUserID, - ToUserID: req.CommID.ToUserID, + FromUserID: req.FromUserID, + ToUserID: req.ToUserID, ReqMsg: req.ReqMsg, - OperationID: req.CommID.OperationID, + OperationID: tracelog.GetOperationID(ctx), } resp := &cbApi.CallbackBeforeAddFriendResp{ CommonCallbackResp: &callbackResp, } //utils.CopyStructFields(req, msg.MsgData) - defer log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp) - if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend.CallbackTimeOut); err != nil { + defer log.NewDebug(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), commonCallbackReq, *resp) + if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil { callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrMsg = err.Error() - if !config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue { + if !*config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue { callbackResp.ActionCode = constant.ActionForbidden return callbackResp } else { diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 2e53e5bb9..52b04b434 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -120,7 +120,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil { return nil, err } - if err := callbackBeforeAddFriendV1(req); err != nil { + if err := callbackBeforeAddFriendV1(ctx, req); err != nil { return nil, err } @@ -140,7 +140,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq if err = s.FriendInterface.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil { return nil, err } - chat.FriendApplicationNotification(req) + chat.FriendApplicationNotification(ctx, req) return resp, nil } @@ -177,7 +177,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res if err != nil { return nil, err } - chat.FriendApplicationApprovedNotification(req) + chat.FriendApplicationApprovedNotification(ctx, req) return resp, nil } if req.HandleResult == constant.FriendResponseRefuse { @@ -185,7 +185,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res if err != nil { return nil, err } - chat.FriendApplicationRejectedNotification(req) + chat.FriendApplicationRejectedNotification(ctx, req) return resp, nil } return nil, constant.ErrArgs.Wrap("req.HandleResult != -1/1") @@ -199,7 +199,7 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, req.FriendUserID); err != nil { return nil, err } - chat.FriendDeletedNotification(req) + chat.FriendDeletedNotification(ctx, req) return resp, nil } @@ -211,7 +211,7 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri if err := s.FriendInterface.UpdateRemark(ctx, req.OwnerUserID, req.FriendUserID, req.Remark); err != nil { return nil, err } - chat.FriendRemarkSetNotification(tracelog.GetOperationID(ctx), tracelog.GetOpUserID(ctx), req.OwnerUserID, req.FriendUserID) + chat.FriendRemarkSetNotification(ctx, req.OwnerUserID, req.FriendUserID) return resp, nil } diff --git a/internal/rpc/msg/friend_notification.go b/internal/rpc/msg/friend_notification.go index dffb2460f..fe3979d5e 100644 --- a/internal/rpc/msg/friend_notification.go +++ b/internal/rpc/msg/friend_notification.go @@ -5,6 +5,7 @@ import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" + "Open_IM/pkg/common/tracelog" pbFriend "Open_IM/pkg/proto/friend" open_im_sdk "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" @@ -90,27 +91,27 @@ func friendNotification(operationID, fromUserID, toUserID string, contentType in Notification(&n) } -func FriendApplicationNotification(operationID string, req *pbFriend.AddFriendReq) { +func FriendApplicationNotification(ctx context.Context, req *pbFriend.AddFriendReq) { FriendApplicationTips := open_im_sdk.FriendApplicationTips{FromToUserID: &open_im_sdk.FromToUserID{}} FriendApplicationTips.FromToUserID.FromUserID = req.FromUserID FriendApplicationTips.FromToUserID.ToUserID = req.ToUserID - friendNotification(operationID, req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &FriendApplicationTips) + friendNotification(tracelog.GetOperationID(ctx), req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &FriendApplicationTips) } -func FriendApplicationApprovedNotification(operationID string, req *pbFriend.RespondFriendApplyReq) { +func FriendApplicationApprovedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) { FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}} FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID FriendApplicationApprovedTips.HandleMsg = req.HandleMsg - friendNotification(operationID, req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips) + friendNotification(tracelog.GetOperationID(ctx), req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips) } -func FriendApplicationRejectedNotification(operationID string, req *pbFriend.RespondFriendApplyReq) { +func FriendApplicationRejectedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) { FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}} FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID FriendApplicationApprovedTips.HandleMsg = req.HandleMsg - friendNotification(operationID, req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &FriendApplicationApprovedTips) + friendNotification(tracelog.GetOperationID(ctx), req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &FriendApplicationApprovedTips) } func FriendAddedNotification(ctx context.Context, operationID, opUserID, fromUserID, toUserID string) { @@ -132,41 +133,41 @@ func FriendAddedNotification(ctx context.Context, operationID, opUserID, fromUse friendNotification(operationID, fromUserID, toUserID, constant.FriendAddedNotification, &friendAddedTips) } -func FriendDeletedNotification(operationID string, req *pbFriend.DeleteFriendReq) { +func FriendDeletedNotification(ctx context.Context, req *pbFriend.DeleteFriendReq) { friendDeletedTips := open_im_sdk.FriendDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}} friendDeletedTips.FromToUserID.FromUserID = req.OwnerUserID friendDeletedTips.FromToUserID.ToUserID = req.FriendUserID - friendNotification(operationID, req.OwnerUserID, req.FriendUserID, constant.FriendDeletedNotification, &friendDeletedTips) + friendNotification(tracelog.GetOperationID(ctx), req.OwnerUserID, req.FriendUserID, constant.FriendDeletedNotification, &friendDeletedTips) } -func FriendRemarkSetNotification(operationID, fromUserID, toUserID string) { +func FriendRemarkSetNotification(ctx context.Context, fromUserID, toUserID string) { friendInfoChangedTips := open_im_sdk.FriendInfoChangedTips{FromToUserID: &open_im_sdk.FromToUserID{}} friendInfoChangedTips.FromToUserID.FromUserID = fromUserID friendInfoChangedTips.FromToUserID.ToUserID = toUserID - friendNotification(operationID, fromUserID, toUserID, constant.FriendRemarkSetNotification, &friendInfoChangedTips) + friendNotification(tracelog.GetOperationID(ctx), fromUserID, toUserID, constant.FriendRemarkSetNotification, &friendInfoChangedTips) } -func BlackAddedNotification(operationID string, req *pbFriend.AddBlackReq) { +func BlackAddedNotification(ctx context.Context, req *pbFriend.AddBlackReq) { blackAddedTips := open_im_sdk.BlackAddedTips{FromToUserID: &open_im_sdk.FromToUserID{}} blackAddedTips.FromToUserID.FromUserID = req.OwnerUserID blackAddedTips.FromToUserID.ToUserID = req.BlackUserID - friendNotification(operationID, req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &blackAddedTips) + friendNotification(tracelog.GetOperationID(ctx), req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &blackAddedTips) } -func BlackDeletedNotification(operationID string, req *pbFriend.RemoveBlackReq) { +func BlackDeletedNotification(ctx context.Context, req *pbFriend.RemoveBlackReq) { blackDeletedTips := open_im_sdk.BlackDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}} blackDeletedTips.FromToUserID.FromUserID = req.OwnerUserID blackDeletedTips.FromToUserID.ToUserID = req.BlackUserID - friendNotification(operationID, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips) + friendNotification(tracelog.GetOperationID(ctx), req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips) } // send to myself -func UserInfoUpdatedNotification(operationID, opUserID string, changedUserID string) { +func UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) { selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: changedUserID} - friendNotification(operationID, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips) + friendNotification(tracelog.GetOperationID(ctx), opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips) } -func FriendInfoUpdatedNotification(operationID, changedUserID string, needNotifiedUserID string, opUserID string) { +func FriendInfoUpdatedNotification(ctx context.Context, changedUserID string, needNotifiedUserID string, opUserID string) { selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: changedUserID} - friendNotification(operationID, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips) + friendNotification(tracelog.GetOperationID(ctx), opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips) } diff --git a/pkg/proto/sdk_ws/ws.proto b/pkg/proto/sdk_ws/ws.proto index e86454cb1..11594fce1 100644 --- a/pkg/proto/sdk_ws/ws.proto +++ b/pkg/proto/sdk_ws/ws.proto @@ -420,12 +420,6 @@ message OrganizationChangedTips{ //////////////////////friend///////////////////// -//message FriendInfo{ -// UserInfo OwnerUser = 1; -// string Remark = 2; -// uint64 CreateTime = 3; -// UserInfo FriendUser = 4; -//} message FriendApplication{ int64 addTime = 1; @@ -440,18 +434,18 @@ message FromToUserID{ //FromUserID apply to add ToUserID message FriendApplicationTips{ - FromToUserID fromToUserID = 1; + FromToUserID fromToUserID = 1; //from:发起者; to:接收者 } //FromUserID accept or reject ToUserID message FriendApplicationApprovedTips{ - FromToUserID fromToUserID = 1; + FromToUserID fromToUserID = 1; //from:同意者;to:请求发起者 string handleMsg = 2; } //FromUserID accept or reject ToUserID message FriendApplicationRejectedTips{ - FromToUserID fromToUserID = 1; + FromToUserID fromToUserID = 1; //from:拒绝者;to:请求发起者 string handleMsg = 2; } @@ -466,21 +460,21 @@ message FriendAddedTips{ // FromUserID deleted a friend ToUserID message FriendDeletedTips{ - FromToUserID fromToUserID = 1; + FromToUserID fromToUserID = 1; //from:owner; to:friend } message BlackAddedTips{ - FromToUserID fromToUserID = 1; + FromToUserID fromToUserID = 1; //from:owner; to:black } message BlackDeletedTips{ - FromToUserID fromToUserID = 1; + FromToUserID fromToUserID = 1; //from:owner; to:black } message FriendInfoChangedTips{ - FromToUserID fromToUserID = 1; + FromToUserID fromToUserID = 1; //from:changed; to:friend } //////////////////////user///////////////////// message UserInfoUpdatedTips{