Skip to content

Commit

Permalink
Prevent panic in stopwatch (#10670) (#10673)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Mar 8, 2020
1 parent 931ddfe commit 66b3178
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions routers/api/v1/repo/issue_stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package repo

import (
"errors"
"net/http"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -172,19 +173,21 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I

if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
ctx.Status(http.StatusForbidden)
return nil, err
return nil, errors.New("Unable to write to PRs")
}

if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
ctx.Status(http.StatusForbidden)
return nil, err
return nil, errors.New("Cannot use time tracker")
}

if models.StopwatchExists(ctx.User.ID, issue.ID) != shouldExist {
if shouldExist {
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
err = errors.New("cannot stop/cancel a non existent stopwatch")
} else {
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot start a stopwatch again if it already exists")
err = errors.New("cannot start a stopwatch again if it already exists")
}
return nil, err
}
Expand Down

0 comments on commit 66b3178

Please sign in to comment.