Skip to content

Commit

Permalink
fix: prevent exposure of database error messages in GET comment response
Browse files Browse the repository at this point in the history
  • Loading branch information
Justhiro55 committed Dec 2, 2024
1 parent 7772a29 commit d45be45
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/infrastructure/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
)

type CommentRepository interface {
Expand Down Expand Up @@ -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()

Expand All @@ -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)
Expand Down

0 comments on commit d45be45

Please sign in to comment.