test-errcode
wangchuxiao 2 years ago
parent 5a2a57c706
commit 2d8a538798

@ -102,41 +102,30 @@ func (s *friendServer) Run() {
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.AddBlacklistResp, error) {
log.NewInfo(req.CommID.OperationID, "AddBlacklist args ", req.String())
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
ok := token_verify.CheckAccess(ctx, req.CommID.OpUserID, req.CommID.FromUserID)
if !ok {
err := errors.New("CheckAccess false")
log.NewError(req.CommID.OperationID, err.Error(), req.CommID.OpUserID, req.CommID.FromUserID)
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrNoPermission, err)}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNoPermission, "accress")}, nil
}
black := db.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
err := imdb.InsertInToUserBlackList(black)
err := imdb.InsertInToUserBlackList(ctx, black)
if err != nil {
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrDatabase, err)}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrDatabase, err.Error())}, nil
}
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
etcdConn := getcdv3.GetDefaultConn(ctx, config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
if etcdConn == nil {
errMsg := req.CommID.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.CommID.OperationID, errMsg)
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, "conn is nil")}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
cacheResp, err := cacheClient.DelBlackIDListFromCache(ctx, &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
if err != nil {
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, err.Error())}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
err = errors.New(fmt.Sprintf("call DelBlackIDListFromCache rpc failed code is %d, err is %s, args is %s", cacheResp.CommonResp.ErrCode, cacheResp.CommonResp.ErrMsg, req.CommID.FromUserID))
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, err.Error())}, nil
}
chat.BlackAddedNotification(req)
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrNone, nil)}, nil
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNone, "")}, nil
}
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.AddFriendResp, error) {

@ -2,8 +2,10 @@ package constant
import (
sdkws "Open_IM/pkg/proto/sdk_ws"
"context"
"encoding/json"
"errors"
"gorm.io/gorm"
)
@ -82,13 +84,13 @@ func ToAPIErrWithErr(err error) ErrInfo {
return ErrDefaultOther
}
func Error2CommResp(info ErrInfo, detailErr error) *sdkws.CommonResp {
func Error2CommResp(ctx context.Context, info ErrInfo, detailErrMsg string) *sdkws.CommonResp {
err := &sdkws.CommonResp{
ErrCode: info.ErrCode,
ErrMsg: info.ErrMsg,
}
if detailErr != nil {
err.DetailErrMsg = detailErr.Error()
if detailErrMsg != "" {
err.DetailErrMsg = detailErrMsg
}
return err
}

@ -0,0 +1,55 @@
package im_mysql_model
import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/utils"
"time"
)
type Group struct {
//`json:"operationID" binding:"required"`
//`protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"` `json:"operationID" binding:"required"`
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
GroupName string `gorm:"column:name;size:255" json:"groupName"`
Notification string `gorm:"column:notification;size:255" json:"notification"`
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
Status int32 `gorm:"column:status"`
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
GroupType int32 `gorm:"column:group_type"`
NeedVerification int32 `gorm:"column:need_verification"`
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
}
func (*Group) Create(groupList []*Group) error {
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Create(&groupList).Error, "")
}
func (*Group) Delete(groupList []*Group) error {
return nil
}
func (*Group) Update(groupList []*Group) error {
return nil
}
func (*Group) UpdateByMap(args map[*Group]map[string]interface{}) error {
return nil
}
func (*Group) Find(group []*Group) ([]*Group, error) {
return nil, nil
}
func (*Group) Take(group *Group) (*Group, error) {
return nil, nil
}
func (*Group) Count(group *Group) (int64, error) {
return 0, nil
}

@ -2,11 +2,14 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/trace_log"
"Open_IM/pkg/utils"
"context"
"time"
)
func InsertInToUserBlackList(black db.Black) error {
func InsertInToUserBlackList(ctx context.Context, black db.Black) error {
defer trace_log.SetContextInfo(ctx)
black.CreateTime = time.Now()
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error
}

@ -6,6 +6,7 @@ import (
commonDB "Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"context"
"time"
go_redis "github.com/go-redis/redis/v8"
@ -139,7 +140,7 @@ func IsManagerUserID(OpUserID string) bool {
}
}
func CheckAccess(OpUserID string, OwnerUserID string) bool {
func CheckAccess(ctx context.Context, OpUserID string, OwnerUserID string) bool {
if utils.IsContain(OpUserID, config.Config.Manager.AppManagerUid) {
return true
}

@ -3,6 +3,7 @@ package trace_log
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"context"
"errors"
"fmt"
@ -76,7 +77,7 @@ func SetContextInfo(ctx context.Context, funcName string, err error, args ...int
var funcInfo FuncInfo
funcInfo.Args = make(map[string]interface{})
argsHandle(args, funcInfo.Args)
funcInfo.FuncName = funcName
funcInfo.FuncName = utils.GetSelfFuncName()
funcInfo.Err = err
*t.Funcs = append(*t.Funcs, funcInfo)
}

Loading…
Cancel
Save