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.

style: fix code error handling

LinkinStar5a01fb9fe155
diff --git a/internal/repo/activity/follow_repo.go b/internal/repo/activity/follow_repo.go
index 69462b7a..62e712fb 100644
--- a/internal/repo/activity/follow_repo.go
+++ b/internal/repo/activity/follow_repo.go
@@ -38,7 +38,7 @@ func NewFollowRepo(
}
func (ar *FollowRepo) Follow(ctx context.Context, objectId, userId string) error {
- activityType, _, _, err := ar.activityRepo.GetActivityTypeByObjID(nil, objectId, "follow")
+ activityType, _, _, err := ar.activityRepo.GetActivityTypeByObjID(ctx, objectId, "follow")
if err != nil {
return err
}
diff --git a/internal/repo/answer_repo.go b/internal/repo/answer_repo.go
index e9e117b5..6092f9d9 100644
--- a/internal/repo/answer_repo.go
+++ b/internal/repo/answer_repo.go
@@ -44,13 +44,13 @@ func NewAnswerRepo(
func (ar *answerRepo) AddAnswer(ctx context.Context, answer *entity.Answer) (err error) {
ID, err := ar.uniqueIDRepo.GenUniqueIDStr(ctx, answer.TableName())
if err != nil {
- errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
answer.ID = ID
_, err = ar.data.DB.Insert(answer)
if err != nil {
- errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return nil
}
diff --git a/internal/repo/collection/collection_repo.go b/internal/repo/collection/collection_repo.go
index 16170e3a..691a35f5 100644
--- a/internal/repo/collection/collection_repo.go
+++ b/internal/repo/collection/collection_repo.go
@@ -44,7 +44,7 @@ func (cr *collectionRepo) AddCollection(ctx context.Context, collection *entity.
func (cr *collectionRepo) RemoveCollection(ctx context.Context, id string) (err error) {
_, err = cr.data.DB.Where("id =?", id).Delete(&entity.Collection{})
if err != nil {
- errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return nil
}
diff --git a/internal/schema/follow_schema.go b/internal/schema/follow_schema.go
index b978acb5..c6f8e802 100644
--- a/internal/schema/follow_schema.go
+++ b/internal/schema/follow_schema.go
@@ -3,9 +3,9 @@ package schema
// FollowReq follow object request
type FollowReq struct {
// object id
- ObjectID string `validate:"required"form:"object_id" json:"object_id"`
+ ObjectID string `validate:"required" form:"object_id" json:"object_id"`
// is cancel
- IsCancel bool `validate:"omitempty"form:"is_cancel" json:"is_cancel"`
+ IsCancel bool `validate:"omitempty" form:"is_cancel" json:"is_cancel"`
}
// FollowResp response object's follows and current user follow status
diff --git a/internal/schema/vote_schema.go b/internal/schema/vote_schema.go
index f1602902..ec37ebc8 100644
--- a/internal/schema/vote_schema.go
+++ b/internal/schema/vote_schema.go
@@ -1,8 +1,8 @@
package schema
type VoteReq struct {
- ObjectID string `validate:"required"form:"object_id" json:"object_id"` // id
- IsCancel bool `validate:"omitempty"form:"is_cancel" json:"is_cancel"` // is cancel
+ ObjectID string `validate:"required" form:"object_id" json:"object_id"` // id
+ IsCancel bool `validate:"omitempty" form:"is_cancel" json:"is_cancel"` // is cancel
}
type VoteDTO struct {
diff --git a/internal/service/export/email_service.go b/internal/service/export/email_service.go
index 56dd5530..a8347e3d 100644
--- a/internal/service/export/email_service.go
+++ b/internal/service/export/email_service.go
@@ -198,6 +198,9 @@ func (es *EmailService) ChangeEmailTemplate(changeEmailUrl string) (title, body
}
tmpl, err = template.New("email_change_body").Parse(ec.ChangeBody)
+ if err != nil {
+ return "", "", err
+ }
err = tmpl.Execute(bodyBuf, templateData)
if err != nil {
return "", "", err
diff --git a/internal/service/search_service.go b/internal/service/search_service.go
index 817c2318..0602425e 100644
--- a/internal/service/search_service.go
+++ b/internal/service/search_service.go
@@ -89,5 +89,5 @@ func (ss *SearchService) Search(ctx context.Context, dto *schema.SearchDTO) (res
ss.objectSearch.Parse(dto)
resp, total, err = ss.objectSearch.Search(ctx)
}
- return resp, total, extra, nil
+ return resp, total, extra, err
}