aboutsummaryrefslogtreecommitdiff
path: root/routers/repo
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-03-22 13:20:29 -0400
committerUnknwon <u@gogs.io>2017-03-22 13:20:29 -0400
commit85a050fca70446ea7a9e10266bbe083d5d8b63ea (patch)
tree23d3fcc2ce2fbd7f289477c1214ac0768e24d85b /routers/repo
parentbb86d66496078b8c2fb242b6286d682ff9d5aa2f (diff)
issue: fix redirect to random issue if index does not exist (#4315)
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/issue.go24
-rw-r--r--routers/repo/pull.go6
2 files changed, 12 insertions, 18 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 3305b8ed..bd60890a 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -5,7 +5,6 @@
package repo
import (
- "errors"
"fmt"
"io"
"io/ioutil"
@@ -19,6 +18,7 @@ import (
log "gopkg.in/clog.v1"
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/models/errors"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/form"
@@ -497,13 +497,15 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["RequireDropzone"] = true
renderAttachmentSettings(ctx)
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ index := ctx.ParamsInt64(":index")
+ if index <= 0 {
+ ctx.NotFound()
+ return
+ }
+
+ issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, index)
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.Handle(404, "GetIssueByIndex", err)
- } else {
- ctx.Handle(500, "GetIssueByIndex", err)
- }
+ ctx.NotFoundOrServerError("GetIssueByIndex", errors.IsIssueNotExist, err)
return
}
ctx.Data["Title"] = issue.Title
@@ -653,11 +655,7 @@ func ViewIssue(ctx *context.Context) {
func getActionIssue(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.Error(404, "GetIssueByIndex")
- } else {
- ctx.Handle(500, "GetIssueByIndex", err)
- }
+ ctx.NotFoundOrServerError("GetIssueByIndex", errors.IsIssueNotExist, err)
return nil
}
return issue
@@ -807,7 +805,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
func NewComment(ctx *context.Context, f form.CreateComment) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
+ ctx.NotFoundOrServerError("GetIssueByIndex", errors.IsIssueNotExist, err)
return
}
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 9184c5e8..aa61dcd9 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -142,11 +142,7 @@ func ForkPost(ctx *context.Context, f form.CreateRepo) {
func checkPullInfo(ctx *context.Context) *models.Issue {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.Handle(404, "GetIssueByIndex", err)
- } else {
- ctx.Handle(500, "GetIssueByIndex", err)
- }
+ ctx.NotFoundOrServerError("GetIssueByIndex", errors.IsIssueNotExist, err)
return nil
}
ctx.Data["Title"] = issue.Title