From d45be454bd436bbe0c2f8414041e6b75ee468f94 Mon Sep 17 00:00:00 2001 From: JustHiro55 Date: Mon, 2 Dec 2024 16:01:37 +0900 Subject: [PATCH] fix: prevent exposure of database error messages in GET comment response --- app/infrastructure/comment.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/infrastructure/comment.go b/app/infrastructure/comment.go index 60c57bf..47747c0 100644 --- a/app/infrastructure/comment.go +++ b/app/infrastructure/comment.go @@ -5,6 +5,7 @@ import ( "time" "github.com/jmoiron/sqlx" + "github.com/pkg/errors" ) type CommentRepository interface { @@ -35,7 +36,7 @@ func (ur *commentRepositoryImpl) SelectCommentsByWorksID(worksID string) ([]*ent rows, err := ur.db.Queryx(query, worksID) if err != nil { - return nil, err + return nil, errors.New("failed to retrieve comments") } defer rows.Close() @@ -49,15 +50,15 @@ func (ur *commentRepositoryImpl) SelectCommentsByWorksID(worksID string) ([]*ent &comment.CommentUserProfile.DisplayName, &comment.CommentUserProfile.Icon, ) if err != nil { - return nil, err + return nil, errors.New("failed to parse comment data") } comment.CreatedAt, err = time.Parse("2006-01-02 15:04:05", string(createdAt)) if err != nil { - return nil, err + return nil, errors.New("failed to parse created_at timestamp") } comment.UpdatedAt, err = time.Parse("2006-01-02 15:04:05", string(updatedAt)) if err != nil { - return nil, err + return nil, errors.New("failed to parse updated_at timestamp") } comments = append(comments, &comment)