Skip to content

Commit 43bbc54

Browse files
lunnyzeripathwxiaoguang
authored
Fix 500 when a comment was deleted which has a notification (go-gitea#17550)
* Fix 500 when a comment was deleted which has a notification * Tolerate missing Comment in other places too Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Andrew Thornton <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 33fca2b commit 43bbc54

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

models/notification.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,13 @@ func (n *Notification) loadComment(e db.Engine) (err error) {
434434
if n.Comment == nil && n.CommentID != 0 {
435435
n.Comment, err = getCommentByID(e, n.CommentID)
436436
if err != nil {
437-
return fmt.Errorf("GetCommentByID [%d] for issue ID [%d]: %v", n.CommentID, n.IssueID, err)
437+
if IsErrCommentNotExist(err) {
438+
return ErrCommentNotExist{
439+
ID: n.CommentID,
440+
IssueID: n.IssueID,
441+
}
442+
}
443+
return err
438444
}
439445
}
440446
return nil
@@ -488,7 +494,7 @@ type NotificationList []*Notification
488494
func (nl NotificationList) LoadAttributes() (err error) {
489495
for i := 0; i < len(nl); i++ {
490496
err = nl[i].LoadAttributes()
491-
if err != nil {
497+
if err != nil && !IsErrCommentNotExist(err) {
492498
return
493499
}
494500
}

routers/api/v1/notify/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
121121
return
122122
}
123123
err = nl.LoadAttributes()
124-
if err != nil {
124+
if err != nil && !models.IsErrCommentNotExist(err) {
125125
ctx.InternalServerError(err)
126126
return
127127
}

routers/api/v1/notify/threads.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func GetThread(ctx *context.APIContext) {
4040
if n == nil {
4141
return
4242
}
43-
if err := n.LoadAttributes(); err != nil {
43+
if err := n.LoadAttributes(); err != nil && !models.IsErrCommentNotExist(err) {
4444
ctx.InternalServerError(err)
4545
return
4646
}
@@ -92,7 +92,7 @@ func ReadThread(ctx *context.APIContext) {
9292
ctx.InternalServerError(err)
9393
return
9494
}
95-
if err = notif.LoadAttributes(); err != nil {
95+
if err = notif.LoadAttributes(); err != nil && !models.IsErrCommentNotExist(err) {
9696
ctx.InternalServerError(err)
9797
return
9898
}

0 commit comments

Comments
 (0)