Error code standardization

test-errcode
skiffer-git 2 years ago
parent e7eee16cf1
commit 839af18f49

@ -6,14 +6,17 @@ import (
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http" "Open_IM/pkg/common/http"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/common/tracelog"
pbFriend "Open_IM/pkg/proto/friend" pbFriend "Open_IM/pkg/proto/friend"
"context"
//"Open_IM/pkg/proto/msg" //"Open_IM/pkg/proto/msg"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
http2 "net/http" http2 "net/http"
) )
func callbackBeforeAddFriendV1(req *pbFriend.AddFriendReq) error { func callbackBeforeAddFriendV1(ctx context.Context, req *pbFriend.AddFriendReq) error {
resp := callbackBeforeAddFriend(req) resp := callbackBeforeAddFriend(ctx, req)
if resp.ErrCode != 0 { if resp.ErrCode != 0 {
return (&constant.ErrInfo{ return (&constant.ErrInfo{
ErrCode: resp.ErrCode, ErrCode: resp.ErrCode,
@ -23,28 +26,28 @@ func callbackBeforeAddFriendV1(req *pbFriend.AddFriendReq) error {
return nil return nil
} }
func callbackBeforeAddFriend(req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp { func callbackBeforeAddFriend(ctx context.Context, req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: req.CommID.OperationID} callbackResp := cbApi.CommonCallbackResp{OperationID: tracelog.GetOperationID(ctx)}
if !config.Config.Callback.CallbackBeforeAddFriend.Enable { if !config.Config.Callback.CallbackBeforeAddFriend.Enable {
return callbackResp return callbackResp
} }
log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), req.String())
commonCallbackReq := &cbApi.CallbackBeforeAddFriendReq{ commonCallbackReq := &cbApi.CallbackBeforeAddFriendReq{
CallbackCommand: constant.CallbackBeforeAddFriendCommand, CallbackCommand: constant.CallbackBeforeAddFriendCommand,
FromUserID: req.CommID.FromUserID, FromUserID: req.FromUserID,
ToUserID: req.CommID.ToUserID, ToUserID: req.ToUserID,
ReqMsg: req.ReqMsg, ReqMsg: req.ReqMsg,
OperationID: req.CommID.OperationID, OperationID: tracelog.GetOperationID(ctx),
} }
resp := &cbApi.CallbackBeforeAddFriendResp{ resp := &cbApi.CallbackBeforeAddFriendResp{
CommonCallbackResp: &callbackResp, CommonCallbackResp: &callbackResp,
} }
//utils.CopyStructFields(req, msg.MsgData) //utils.CopyStructFields(req, msg.MsgData)
defer log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp) 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.CallbackTimeOut); err != nil { if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error() callbackResp.ErrMsg = err.Error()
if !config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue { if !*config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue {
callbackResp.ActionCode = constant.ActionForbidden callbackResp.ActionCode = constant.ActionForbidden
return callbackResp return callbackResp
} else { } else {

@ -120,7 +120,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil { if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
return nil, err return nil, err
} }
if err := callbackBeforeAddFriendV1(req); err != nil { if err := callbackBeforeAddFriendV1(ctx, req); err != nil {
return nil, err 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 { if err = s.FriendInterface.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil {
return nil, err return nil, err
} }
chat.FriendApplicationNotification(req) chat.FriendApplicationNotification(ctx, req)
return resp, nil return resp, nil
} }
@ -177,7 +177,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
if err != nil { if err != nil {
return nil, err return nil, err
} }
chat.FriendApplicationApprovedNotification(req) chat.FriendApplicationApprovedNotification(ctx, req)
return resp, nil return resp, nil
} }
if req.HandleResult == constant.FriendResponseRefuse { if req.HandleResult == constant.FriendResponseRefuse {
@ -185,7 +185,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
if err != nil { if err != nil {
return nil, err return nil, err
} }
chat.FriendApplicationRejectedNotification(req) chat.FriendApplicationRejectedNotification(ctx, req)
return resp, nil return resp, nil
} }
return nil, constant.ErrArgs.Wrap("req.HandleResult != -1/1") 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 { if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, req.FriendUserID); err != nil {
return nil, err return nil, err
} }
chat.FriendDeletedNotification(req) chat.FriendDeletedNotification(ctx, req)
return resp, nil 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 { if err := s.FriendInterface.UpdateRemark(ctx, req.OwnerUserID, req.FriendUserID, req.Remark); err != nil {
return nil, err 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 return resp, nil
} }

@ -5,6 +5,7 @@ import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant" "Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/common/tracelog"
pbFriend "Open_IM/pkg/proto/friend" pbFriend "Open_IM/pkg/proto/friend"
open_im_sdk "Open_IM/pkg/proto/sdk_ws" open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
@ -90,27 +91,27 @@ func friendNotification(operationID, fromUserID, toUserID string, contentType in
Notification(&n) 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 := open_im_sdk.FriendApplicationTips{FromToUserID: &open_im_sdk.FromToUserID{}}
FriendApplicationTips.FromToUserID.FromUserID = req.FromUserID FriendApplicationTips.FromToUserID.FromUserID = req.FromUserID
FriendApplicationTips.FromToUserID.ToUserID = req.ToUserID 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 := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg 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 := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg 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) { 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) 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 := open_im_sdk.FriendDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
friendDeletedTips.FromToUserID.FromUserID = req.OwnerUserID friendDeletedTips.FromToUserID.FromUserID = req.OwnerUserID
friendDeletedTips.FromToUserID.ToUserID = req.FriendUserID 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 := open_im_sdk.FriendInfoChangedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
friendInfoChangedTips.FromToUserID.FromUserID = fromUserID friendInfoChangedTips.FromToUserID.FromUserID = fromUserID
friendInfoChangedTips.FromToUserID.ToUserID = toUserID 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 := open_im_sdk.BlackAddedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
blackAddedTips.FromToUserID.FromUserID = req.OwnerUserID blackAddedTips.FromToUserID.FromUserID = req.OwnerUserID
blackAddedTips.FromToUserID.ToUserID = req.BlackUserID 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 := open_im_sdk.BlackDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
blackDeletedTips.FromToUserID.FromUserID = req.OwnerUserID blackDeletedTips.FromToUserID.FromUserID = req.OwnerUserID
blackDeletedTips.FromToUserID.ToUserID = req.BlackUserID 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 // 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} 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} selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: changedUserID}
friendNotification(operationID, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips) friendNotification(tracelog.GetOperationID(ctx), opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
} }

@ -420,12 +420,6 @@ message OrganizationChangedTips{
//////////////////////friend///////////////////// //////////////////////friend/////////////////////
//message FriendInfo{
// UserInfo OwnerUser = 1;
// string Remark = 2;
// uint64 CreateTime = 3;
// UserInfo FriendUser = 4;
//}
message FriendApplication{ message FriendApplication{
int64 addTime = 1; int64 addTime = 1;
@ -440,18 +434,18 @@ message FromToUserID{
//FromUserID apply to add ToUserID //FromUserID apply to add ToUserID
message FriendApplicationTips{ message FriendApplicationTips{
FromToUserID fromToUserID = 1; FromToUserID fromToUserID = 1; //from to
} }
//FromUserID accept or reject ToUserID //FromUserID accept or reject ToUserID
message FriendApplicationApprovedTips{ message FriendApplicationApprovedTips{
FromToUserID fromToUserID = 1; FromToUserID fromToUserID = 1; //fromto
string handleMsg = 2; string handleMsg = 2;
} }
//FromUserID accept or reject ToUserID //FromUserID accept or reject ToUserID
message FriendApplicationRejectedTips{ message FriendApplicationRejectedTips{
FromToUserID fromToUserID = 1; FromToUserID fromToUserID = 1; //fromto
string handleMsg = 2; string handleMsg = 2;
} }
@ -466,21 +460,21 @@ message FriendAddedTips{
// FromUserID deleted a friend ToUserID // FromUserID deleted a friend ToUserID
message FriendDeletedTips{ message FriendDeletedTips{
FromToUserID fromToUserID = 1; FromToUserID fromToUserID = 1; //fromowner tofriend
} }
message BlackAddedTips{ message BlackAddedTips{
FromToUserID fromToUserID = 1; FromToUserID fromToUserID = 1; //fromowner toblack
} }
message BlackDeletedTips{ message BlackDeletedTips{
FromToUserID fromToUserID = 1; FromToUserID fromToUserID = 1; //fromowner toblack
} }
message FriendInfoChangedTips{ message FriendInfoChangedTips{
FromToUserID fromToUserID = 1; FromToUserID fromToUserID = 1; //fromchanged tofriend
} }
//////////////////////user///////////////////// //////////////////////user/////////////////////
message UserInfoUpdatedTips{ message UserInfoUpdatedTips{

Loading…
Cancel
Save