Skip to content

Commit 33c5e5e

Browse files
authored
Prevent panic in stopwatch (#10670)
Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 1966f42 commit 33c5e5e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: routers/api/v1/repo/issue_stopwatch.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package repo
66

77
import (
8+
"errors"
89
"net/http"
910

1011
"code.gitea.io/gitea/models"
@@ -173,19 +174,21 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I
173174

174175
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
175176
ctx.Status(http.StatusForbidden)
176-
return nil, err
177+
return nil, errors.New("Unable to write to PRs")
177178
}
178179

179180
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
180181
ctx.Status(http.StatusForbidden)
181-
return nil, err
182+
return nil, errors.New("Cannot use time tracker")
182183
}
183184

184185
if models.StopwatchExists(ctx.User.ID, issue.ID) != shouldExist {
185186
if shouldExist {
186187
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
188+
err = errors.New("cannot stop/cancel a non existent stopwatch")
187189
} else {
188190
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot start a stopwatch again if it already exists")
191+
err = errors.New("cannot start a stopwatch again if it already exists")
189192
}
190193
return nil, err
191194
}

0 commit comments

Comments
 (0)