Skip to content

Commit 66b3178

Browse files
authored
Prevent panic in stopwatch (#10670) (#10673)
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 931ddfe commit 66b3178

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

routers/api/v1/repo/issue_stopwatch.go

Lines changed: 5 additions & 2 deletions
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"
@@ -172,19 +173,21 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I
172173

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

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

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

0 commit comments

Comments
 (0)