mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-02 10:18:45 +08:00
fix: wrap the error of group user and thrid
This commit is contained in:
parent
532f6acb5d
commit
4a544faf26
@ -120,12 +120,12 @@ func (s *groupServer) NotificationUserInfoUpdate(ctx context.Context, req *pbgro
|
||||
groupIDs = append(groupIDs, member.GroupID)
|
||||
}
|
||||
for _, groupID := range groupIDs {
|
||||
if err := s.Notification.GroupMemberInfoSetNotification(ctx, groupID, req.UserID); err != nil {
|
||||
log.ZError(ctx, "NotificationUserInfoUpdate setGroupMemberInfo notification failed", err, "groupID", groupID)
|
||||
if err = s.Notification.GroupMemberInfoSetNotification(ctx, groupID, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := s.db.DeleteGroupMemberHash(ctx, groupIDs); err != nil {
|
||||
log.ZError(ctx, "NotificationUserInfoUpdate DeleteGroupMemberHash", err, "groupID", groupIDs)
|
||||
if err = s.db.DeleteGroupMemberHash(ctx, groupIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pbgroup.NotificationUserInfoUpdateResp{}, nil
|
||||
|
||||
@ -209,7 +209,7 @@ func (t *thirdServer) InitiateFormData(ctx context.Context, req *third.InitiateF
|
||||
}
|
||||
uid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err, "uuid NewRandom failed")
|
||||
}
|
||||
if key == "" {
|
||||
date := time.Now().Format("20060102")
|
||||
@ -224,7 +224,7 @@ func (t *thirdServer) InitiateFormData(ctx context.Context, req *third.InitiateF
|
||||
}
|
||||
mateData, err := json.Marshal(&mate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err, "marshal failed")
|
||||
}
|
||||
resp, err := t.s3dataBase.FormData(ctx, key, req.Size, req.ContentType, duration)
|
||||
if err != nil {
|
||||
|
||||
@ -17,6 +17,7 @@ package third
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
@ -54,9 +55,9 @@ func Start(config *config.GlobalConfig, client discoveryregistry.SvcDiscoveryReg
|
||||
}
|
||||
apiURL := config.Object.ApiURL
|
||||
if apiURL == "" {
|
||||
return fmt.Errorf("api url is empty")
|
||||
return errs.Wrap(fmt.Errorf("api is empty"))
|
||||
}
|
||||
if _, parseErr := url.Parse(config.Object.ApiURL); parseErr != nil {
|
||||
if _, err := url.Parse(config.Object.ApiURL); err != nil {
|
||||
return err
|
||||
}
|
||||
if apiURL[len(apiURL)-1] != '/' {
|
||||
|
||||
@ -16,7 +16,7 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
@ -78,7 +78,7 @@ func Start(config *config.GlobalConfig, client registry.SvcDiscoveryRegistry, se
|
||||
}
|
||||
users := make([]*tablerelation.UserModel, 0)
|
||||
if len(config.IMAdmin.UserID) != len(config.IMAdmin.Nickname) {
|
||||
return errors.New("len(s.config.AppNotificationAdmin.AppManagerUid) != len(s.config.AppNotificationAdmin.Nickname)")
|
||||
return errs.Wrap(fmt.Errorf("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname"))
|
||||
}
|
||||
for k, v := range config.IMAdmin.UserID {
|
||||
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.IMAdmin.Nickname[k], AppMangerLevel: constant.AppNotificationAdmin})
|
||||
@ -113,9 +113,6 @@ func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesig
|
||||
return nil, err
|
||||
}
|
||||
resp.UsersInfo = convert.UsersDB2Pb(users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -139,7 +136,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
|
||||
}
|
||||
if req.UserInfo.Nickname != "" || req.UserInfo.FaceURL != "" {
|
||||
if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
||||
log.ZError(ctx, "NotificationUserInfoUpdate", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for _, friendID := range friends {
|
||||
@ -149,7 +146,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
|
||||
return nil, err
|
||||
}
|
||||
if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
||||
log.ZError(ctx, "NotificationUserInfoUpdate", err, "userID", req.UserInfo.UserID)
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@ -174,7 +171,7 @@ func (s *userServer) UpdateUserInfoEx(ctx context.Context, req *pbuser.UpdateUse
|
||||
}
|
||||
if req.UserInfo.Nickname != nil || req.UserInfo.FaceURL != nil {
|
||||
if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
||||
log.ZError(ctx, "NotificationUserInfoUpdate", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for _, friendID := range friends {
|
||||
@ -184,7 +181,7 @@ func (s *userServer) UpdateUserInfoEx(ctx context.Context, req *pbuser.UpdateUse
|
||||
return nil, err
|
||||
}
|
||||
if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
||||
log.ZError(ctx, "NotificationUserInfoUpdate", err, "userID", req.UserInfo.UserID)
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
2
pkg/common/db/cache/meta_cache.go
vendored
2
pkg/common/db/cache/meta_cache.go
vendored
@ -131,7 +131,7 @@ func getCache[T any](ctx context.Context, rcClient *rockscache.Client, key strin
|
||||
v, err := rcClient.Fetch2(ctx, key, expire, func() (s string, err error) {
|
||||
t, err = fn(ctx)
|
||||
if err != nil {
|
||||
return "", errs.Wrap(err)
|
||||
return "", err
|
||||
}
|
||||
bs, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
|
||||
2
pkg/common/db/cache/msg.go
vendored
2
pkg/common/db/cache/msg.go
vendored
@ -471,7 +471,7 @@ func (c *msgCache) ParallelSetMessageToCache(ctx context.Context, conversationID
|
||||
|
||||
err := wg.Wait()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, errs.Wrap(err, "wg.Wait failed")
|
||||
}
|
||||
|
||||
return len(msgs), nil
|
||||
|
||||
@ -16,6 +16,7 @@ package mgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
|
||||
"github.com/OpenIMSDK/tools/mgoutil"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
@ -33,7 +34,7 @@ func NewS3Mongo(db *mongo.Database) (relation.ObjectInfoModelInterface, error) {
|
||||
Options: options.Index().SetUnique(true),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
return &S3Mongo{coll: coll}, nil
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ func (u *UserMgo) AddUserCommand(ctx context.Context, userID string, Type int32,
|
||||
}
|
||||
|
||||
_, err := collection.InsertOne(ctx, doc)
|
||||
return err
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
func (u *UserMgo) DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error {
|
||||
@ -170,7 +170,7 @@ func (u *UserMgo) DeleteUserCommand(ctx context.Context, userID string, Type int
|
||||
// No records found to update
|
||||
return errs.Wrap(errs.ErrRecordNotFound)
|
||||
}
|
||||
return err
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, val map[string]any) error {
|
||||
if len(val) == 0 {
|
||||
@ -184,7 +184,7 @@ func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int
|
||||
|
||||
result, err := collection.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
return err
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
|
||||
if result.MatchedCount == 0 {
|
||||
@ -233,7 +233,7 @@ func (u *UserMgo) GetUserCommand(ctx context.Context, userID string, Type int32)
|
||||
}
|
||||
|
||||
if err := cursor.Err(); err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
|
||||
return commands, nil
|
||||
@ -244,7 +244,7 @@ func (u *UserMgo) GetAllUserCommand(ctx context.Context, userID string) ([]*user
|
||||
|
||||
cursor, err := collection.Find(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
@ -261,7 +261,7 @@ func (u *UserMgo) GetAllUserCommand(ctx context.Context, userID string) ([]*user
|
||||
}
|
||||
|
||||
if err := cursor.Decode(&document); err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
|
||||
commandInfo := &user.AllCommandInfoResp{
|
||||
@ -276,7 +276,7 @@ func (u *UserMgo) GetAllUserCommand(ctx context.Context, userID string) ([]*user
|
||||
}
|
||||
|
||||
if err := cursor.Err(); err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
@ -102,12 +102,11 @@ func buildMongoURI(config *config.GlobalConfig) string {
|
||||
maxPoolSize = fmt.Sprint(config.Mongo.MaxPoolSize)
|
||||
}
|
||||
|
||||
uriFormat := "mongodb://%s/%s?maxPoolSize=%s"
|
||||
if username != "" && password != "" {
|
||||
uriFormat = "mongodb://%s:%s@%s/%s?maxPoolSize=%s"
|
||||
return fmt.Sprintf(uriFormat, username, password, address, database, maxPoolSize)
|
||||
|
||||
return fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%s", username, password, address, database, maxPoolSize)
|
||||
}
|
||||
return fmt.Sprintf(uriFormat, address, database, maxPoolSize)
|
||||
return fmt.Sprintf("mongodb://%s/%s?maxPoolSize=%s", address, database, maxPoolSize)
|
||||
}
|
||||
|
||||
func shouldRetry(err error) bool {
|
||||
|
||||
@ -100,7 +100,7 @@ func (cd *ConnDirect) GetConns(ctx context.Context,
|
||||
for _, port := range ports {
|
||||
conn, err := cd.dialServiceWithoutResolver(ctx, fmt.Sprintf(cd.config.Rpc.ListenIP+":%d", port), append(cd.additionalOpts, opts...)...)
|
||||
if err != nil {
|
||||
fmt.Printf("connect to port %d failed,serviceName %s, IP %s\n", port, serviceName, cd.config.Rpc.ListenIP)
|
||||
return nil, errs.Wrap(fmt.Errorf("connect to port %d failed,serviceName %s, IP %s\n", port, serviceName, cd.config.Rpc.ListenIP))
|
||||
}
|
||||
connections = append(connections, conn)
|
||||
}
|
||||
@ -166,7 +166,7 @@ func (cd *ConnDirect) dialServiceWithoutResolver(ctx context.Context, address st
|
||||
conn, err := grpc.DialContext(ctx, address, options...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errs.Wrap(err)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
||||
|
||||
"github.com/OpenIMSDK/protocol/constant"
|
||||
"github.com/OpenIMSDK/protocol/msg"
|
||||
@ -135,7 +136,7 @@ type Message struct {
|
||||
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry, config *config.GlobalConfig) *Message {
|
||||
conn, err := discov.GetConn(context.Background(), config.RpcRegisterName.OpenImMsgName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
util.ExitWithError(err)
|
||||
}
|
||||
client := msg.NewMsgClient(conn)
|
||||
return &Message{discov: discov, conn: conn, Client: client, Config: config}
|
||||
|
||||
@ -160,7 +160,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
|
||||
tableName := zero.TableName()
|
||||
coll, err := getColl(obj)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get mongo collection %s failed, err: %w", tableName, err)
|
||||
return errs.Wrap(fmt.Errorf("get mongo collection %s failed, err: %w", tableName, err))
|
||||
}
|
||||
var count int
|
||||
defer func() {
|
||||
@ -173,7 +173,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
|
||||
if mysqlErr, ok := err.(*mysql.MySQLError); ok && mysqlErr.Number == 1146 {
|
||||
return nil // table not exist
|
||||
}
|
||||
return fmt.Errorf("find mysql table %s failed, err: %w", tableName, err)
|
||||
return errs.Wrap(fmt.Errorf("find mysql table %s failed, err: %w", tableName, err))
|
||||
}
|
||||
if len(res) == 0 {
|
||||
return nil
|
||||
@ -183,7 +183,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
|
||||
temp[i] = convert(res[i])
|
||||
}
|
||||
if err := insertMany(coll, temp); err != nil {
|
||||
return fmt.Errorf("insert mongo table %s failed, err: %w", tableName, err)
|
||||
return errs.Wrap(fmt.Errorf("insert mongo table %s failed, err: %w", tableName, err))
|
||||
}
|
||||
count += len(res)
|
||||
if len(res) < batch {
|
||||
@ -196,7 +196,7 @@ func NewTask[A interface{ TableName() string }, B any, C any](gormDB *gorm.DB, m
|
||||
func insertMany(coll *mongo.Collection, objs []any) error {
|
||||
if _, err := coll.InsertMany(context.Background(), objs); err != nil {
|
||||
if !mongo.IsDuplicateKeyError(err) {
|
||||
return err
|
||||
return errs.Wrap(err)
|
||||
}
|
||||
}
|
||||
for i := range objs {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user