Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(activity): return err when can not find activity type

LinkinStarsfb757139ae4e
diff --git a/internal/repo/activity_common/activity_repo.go b/internal/repo/activity_common/activity_repo.go
index a59b7085..db1af3d1 100644
--- a/internal/repo/activity_common/activity_repo.go
+++ b/internal/repo/activity_common/activity_repo.go
@@ -63,7 +63,7 @@ func (ar *ActivityRepo) GetActivityTypeByObjKey(ctx context.Context, objectKey,
configKey := fmt.Sprintf("%s.%s", objectKey, action)
cfg, err := ar.configService.GetConfigByKey(ctx, configKey)
if err != nil {
- err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ return 0, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return cfg.ID, nil
}
@@ -71,7 +71,7 @@ func (ar *ActivityRepo) GetActivityTypeByObjKey(ctx context.Context, objectKey,
func (ar *ActivityRepo) GetActivityTypeByConfigKey(ctx context.Context, configKey string) (activityType int, err error) {
cfg, err := ar.configService.GetConfigByKey(ctx, configKey)
if err != nil {
- err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ return 0, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return cfg.ID, nil
}
diff --git a/internal/repo/activity_common/follow.go b/internal/repo/activity_common/follow.go
index 11b5763c..05098277 100644
--- a/internal/repo/activity_common/follow.go
+++ b/internal/repo/activity_common/follow.go
@@ -10,6 +10,7 @@ import (
"github.com/answerdev/answer/internal/service/unique"
"github.com/answerdev/answer/pkg/obj"
"github.com/segmentfault/pacman/errors"
+ "github.com/segmentfault/pacman/log"
)
// FollowRepo follow repository
@@ -71,11 +72,12 @@ func (ar *FollowRepo) GetFollowAmount(ctx context.Context, objectID string) (fol
func (ar *FollowRepo) GetFollowUserIDs(ctx context.Context, objectID string) (userIDs []string, err error) {
objectTypeStr, err := obj.GetObjectTypeStrByObjectID(objectID)
if err != nil {
- return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ return nil, err
}
activityType, err := ar.activityRepo.GetActivityTypeByObjKey(ctx, objectTypeStr, "follow")
if err != nil {
- return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ log.Errorf("can't get activity type by object key: %s", objectTypeStr)
+ return nil, err
}
userIDs = make([]string, 0)