Updates to API 404 responses (#6077)

pull/4299/head^2
John Olheiser 6 years ago committed by techknowlogick
parent d10a668ffc
commit cac9e6e760
  1. 29
      modules/context/api.go
  2. 2
      routers/api/v1/admin/user.go
  3. 40
      routers/api/v1/api.go
  4. 2
      routers/api/v1/org/hook.go
  5. 6
      routers/api/v1/org/member.go
  6. 4
      routers/api/v1/org/team.go
  7. 4
      routers/api/v1/repo/branch.go
  8. 2
      routers/api/v1/repo/collaborators.go
  9. 8
      routers/api/v1/repo/file.go
  10. 2
      routers/api/v1/repo/git_ref.go
  11. 2
      routers/api/v1/repo/hook.go
  12. 10
      routers/api/v1/repo/issue.go
  13. 4
      routers/api/v1/repo/issue_comment.go
  14. 10
      routers/api/v1/repo/issue_label.go
  15. 10
      routers/api/v1/repo/issue_tracked_time.go
  16. 2
      routers/api/v1/repo/key.go
  17. 4
      routers/api/v1/repo/label.go
  18. 4
      routers/api/v1/repo/milestone.go
  19. 24
      routers/api/v1/repo/pull.go
  20. 6
      routers/api/v1/repo/release.go
  21. 10
      routers/api/v1/repo/release_attachment.go
  22. 4
      routers/api/v1/repo/repo.go
  23. 2
      routers/api/v1/user/app.go
  24. 2
      routers/api/v1/user/follower.go
  25. 2
      routers/api/v1/user/gpg_key.go
  26. 6
      routers/api/v1/user/key.go
  27. 2
      routers/api/v1/user/star.go
  28. 2
      routers/api/v1/user/user.go
  29. 2
      routers/api/v1/user/watch.go
  30. 4
      routers/api/v1/utils/hook.go

@ -1,4 +1,5 @@
// Copyright 2016 The Gogs Authors. All rights reserved. // Copyright 2016 The Gogs Authors. All rights reserved.
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -6,6 +7,8 @@ package context
import ( import (
"fmt" "fmt"
"net/url"
"path"
"strings" "strings"
"github.com/go-macaron/csrf" "github.com/go-macaron/csrf"
@ -140,3 +143,29 @@ func ReferencesGitRepo() macaron.Handler {
} }
} }
} }
// NotFound handles 404s for APIContext
// String will replace message, errors will be added to a slice
func (ctx *APIContext) NotFound(objs ...interface{}) {
var message = "Not Found"
var errors []string
for _, obj := range objs {
if err, ok := obj.(error); ok {
errors = append(errors, err.Error())
} else {
message = obj.(string)
}
}
u, err := url.Parse(setting.AppURL)
if err != nil {
ctx.Error(500, "Invalid AppURL", err)
return
}
u.Path = path.Join(u.Path, "api", "swagger")
ctx.JSON(404, map[string]interface{}{
"message": message,
"documentation_url": u.String(),
"errors": errors,
})
}

@ -288,7 +288,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
if err := models.DeletePublicKey(u, ctx.ParamsInt64(":id")); err != nil { if err := models.DeletePublicKey(u, ctx.ParamsInt64(":id")); err != nil {
if models.IsErrKeyNotExist(err) { if models.IsErrKeyNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else if models.IsErrKeyAccessDenied(err) { } else if models.IsErrKeyAccessDenied(err) {
ctx.Error(403, "", "You do not have access to this key") ctx.Error(403, "", "You do not have access to this key")
} else { } else {

@ -74,7 +74,7 @@ import (
api "code.gitea.io/sdk/gitea" api "code.gitea.io/sdk/gitea"
"github.com/go-macaron/binding" "github.com/go-macaron/binding"
macaron "gopkg.in/macaron.v1" "gopkg.in/macaron.v1"
) )
func sudo() macaron.Handler { func sudo() macaron.Handler {
@ -89,7 +89,7 @@ func sudo() macaron.Handler {
user, err := models.GetUserByName(sudo) user, err := models.GetUserByName(sudo)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetUserByName", err) ctx.Error(500, "GetUserByName", err)
} }
@ -124,7 +124,7 @@ func repoAssignment() macaron.Handler {
owner, err = models.GetUserByName(userName) owner, err = models.GetUserByName(userName)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetUserByName", err) ctx.Error(500, "GetUserByName", err)
} }
@ -141,7 +141,7 @@ func repoAssignment() macaron.Handler {
if err == nil { if err == nil {
context.RedirectToRepo(ctx.Context, redirectRepoID) context.RedirectToRepo(ctx.Context, redirectRepoID)
} else if models.IsErrRepoRedirectNotExist(err) { } else if models.IsErrRepoRedirectNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "LookupRepoRedirect", err) ctx.Error(500, "LookupRepoRedirect", err)
} }
@ -160,7 +160,7 @@ func repoAssignment() macaron.Handler {
} }
if !ctx.Repo.HasAccess() { if !ctx.Repo.HasAccess() {
ctx.Status(404) ctx.NotFound()
return return
} }
} }
@ -268,7 +268,7 @@ func reqOrgMembership() macaron.Handler {
if ctx.Org.Organization != nil { if ctx.Org.Organization != nil {
ctx.Error(403, "", "Must be an organization member") ctx.Error(403, "", "Must be an organization member")
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
return return
} }
@ -294,7 +294,7 @@ func reqOrgOwnership() macaron.Handler {
if ctx.Org.Organization != nil { if ctx.Org.Organization != nil {
ctx.Error(403, "", "Must be an organization owner") ctx.Error(403, "", "Must be an organization owner")
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
return return
} }
@ -320,7 +320,7 @@ func orgAssignment(args ...bool) macaron.Handler {
ctx.Org.Organization, err = models.GetOrgByName(ctx.Params(":orgname")) ctx.Org.Organization, err = models.GetOrgByName(ctx.Params(":orgname"))
if err != nil { if err != nil {
if models.IsErrOrgNotExist(err) { if models.IsErrOrgNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetOrgByName", err) ctx.Error(500, "GetOrgByName", err)
} }
@ -332,7 +332,7 @@ func orgAssignment(args ...bool) macaron.Handler {
ctx.Org.Team, err = models.GetTeamByID(ctx.ParamsInt64(":teamid")) ctx.Org.Team, err = models.GetTeamByID(ctx.ParamsInt64(":teamid"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetTeamById", err) ctx.Error(500, "GetTeamById", err)
} }
@ -344,36 +344,36 @@ func orgAssignment(args ...bool) macaron.Handler {
func mustEnableIssues(ctx *context.APIContext) { func mustEnableIssues(ctx *context.APIContext) {
if !ctx.Repo.CanRead(models.UnitTypeIssues) { if !ctx.Repo.CanRead(models.UnitTypeIssues) {
ctx.Status(404) ctx.NotFound()
return return
} }
} }
func mustAllowPulls(ctx *context.Context) { func mustAllowPulls(ctx *context.APIContext) {
if !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) { if !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) {
ctx.Status(404) ctx.NotFound()
return return
} }
} }
func mustEnableIssuesOrPulls(ctx *context.Context) { func mustEnableIssuesOrPulls(ctx *context.APIContext) {
if !ctx.Repo.CanRead(models.UnitTypeIssues) && if !ctx.Repo.CanRead(models.UnitTypeIssues) &&
!(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) { !(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) {
ctx.Status(404) ctx.NotFound()
return return
} }
} }
func mustEnableUserHeatmap(ctx *context.Context) { func mustEnableUserHeatmap(ctx *context.APIContext) {
if !setting.Service.EnableUserHeatmap { if !setting.Service.EnableUserHeatmap {
ctx.Status(404) ctx.NotFound()
return return
} }
} }
func mustNotBeArchived(ctx *context.Context) { func mustNotBeArchived(ctx *context.APIContext) {
if ctx.Repo.Repository.IsArchived { if ctx.Repo.Repository.IsArchived {
ctx.Status(404) ctx.NotFound()
return return
} }
} }
@ -683,8 +683,8 @@ func RegisterRoutes(m *macaron.Macaron) {
}) })
}, orgAssignment(false, true), reqToken(), reqOrgMembership()) }, orgAssignment(false, true), reqToken(), reqOrgMembership())
m.Any("/*", func(ctx *context.Context) { m.Any("/*", func(ctx *context.APIContext) {
ctx.Error(404) ctx.NotFound()
}) })
m.Group("/admin", func() { m.Group("/admin", func() {

@ -164,7 +164,7 @@ func DeleteHook(ctx *context.APIContext) {
hookID := ctx.ParamsInt64(":id") hookID := ctx.ParamsInt64(":id")
if err := models.DeleteWebhookByOrgID(org.ID, hookID); err != nil { if err := models.DeleteWebhookByOrgID(org.ID, hookID); err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "DeleteWebhookByOrgID", err) ctx.Error(500, "DeleteWebhookByOrgID", err)
} }

@ -135,11 +135,11 @@ func IsMember(ctx *context.APIContext) {
} else if userToCheckIsMember { } else if userToCheckIsMember {
ctx.Status(204) ctx.Status(204)
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
return return
} else if ctx.User.ID == userToCheck.ID { } else if ctx.User.ID == userToCheck.ID {
ctx.Status(404) ctx.NotFound()
return return
} }
} }
@ -177,7 +177,7 @@ func IsPublicMember(ctx *context.APIContext) {
if userToCheck.IsPublicMember(ctx.Org.Organization.ID) { if userToCheck.IsPublicMember(ctx.Org.Organization.ID) {
ctx.Status(204) ctx.Status(204)
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
} }

@ -242,7 +242,7 @@ func GetTeamMembers(ctx *context.APIContext) {
ctx.Error(500, "IsOrganizationMember", err) ctx.Error(500, "IsOrganizationMember", err)
return return
} else if !isMember { } else if !isMember {
ctx.Status(404) ctx.NotFound()
return return
} }
team := ctx.Org.Team team := ctx.Org.Team
@ -391,7 +391,7 @@ func getRepositoryByParams(ctx *context.APIContext) *models.Repository {
repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame")) repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetRepositoryByName", err) ctx.Error(500, "GetRepositoryByName", err)
} }

@ -42,13 +42,13 @@ func GetBranch(ctx *context.APIContext) {
// if TreePath != "", then URL contained extra slashes // if TreePath != "", then URL contained extra slashes
// (i.e. "master/subbranch" instead of "master"), so branch does // (i.e. "master/subbranch" instead of "master"), so branch does
// not exist // not exist
ctx.Status(404) ctx.NotFound()
return return
} }
branch, err := ctx.Repo.Repository.GetBranch(ctx.Repo.BranchName) branch, err := ctx.Repo.Repository.GetBranch(ctx.Repo.BranchName)
if err != nil { if err != nil {
if models.IsErrBranchNotExist(err) { if models.IsErrBranchNotExist(err) {
ctx.Error(404, "GetBranch", err) ctx.NotFound(err)
} else { } else {
ctx.Error(500, "GetBranch", err) ctx.Error(500, "GetBranch", err)
} }

@ -92,7 +92,7 @@ func IsCollaborator(ctx *context.APIContext) {
if isColab { if isColab {
ctx.Status(204) ctx.Status(204)
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
} }

@ -40,14 +40,14 @@ func GetRawFile(ctx *context.APIContext) {
// 200: // 200:
// description: success // description: success
if ctx.Repo.Repository.IsEmpty { if ctx.Repo.Repository.IsEmpty {
ctx.Status(404) ctx.NotFound()
return return
} }
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath) blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
if err != nil { if err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetBlobByPath", err) ctx.Error(500, "GetBlobByPath", err)
} }
@ -124,7 +124,7 @@ func GetEditorconfig(ctx *context.APIContext) {
ec, err := ctx.Repo.GetEditorconfig() ec, err := ctx.Repo.GetEditorconfig()
if err != nil { if err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.Error(404, "GetEditorconfig", err) ctx.NotFound(err)
} else { } else {
ctx.Error(500, "GetEditorconfig", err) ctx.Error(500, "GetEditorconfig", err)
} }
@ -134,7 +134,7 @@ func GetEditorconfig(ctx *context.APIContext) {
fileName := ctx.Params("filename") fileName := ctx.Params("filename")
def := ec.GetDefinitionForFilename(fileName) def := ec.GetDefinitionForFilename(fileName)
if def == nil { if def == nil {
ctx.Error(404, "GetDefinitionForFilename", err) ctx.NotFound(err)
return return
} }
ctx.JSON(200, def) ctx.JSON(200, def)

@ -89,7 +89,7 @@ func getGitRefsInternal(ctx *context.APIContext, filter string) {
} }
if len(refs) == 0 { if len(refs) == 0 {
ctx.Status(404) ctx.NotFound()
return return
} }

@ -239,7 +239,7 @@ func DeleteHook(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil { if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "DeleteWebhookByRepoID", err) ctx.Error(500, "DeleteWebhookByRepoID", err)
} }

@ -146,7 +146,7 @@ func GetIssue(ctx *context.APIContext) {
issue, err := models.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -283,7 +283,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -412,7 +412,7 @@ func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -478,7 +478,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -547,7 +547,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }

@ -268,7 +268,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrCommentNotExist(err) { if models.IsErrCommentNotExist(err) {
ctx.Error(404, "GetCommentByID", err) ctx.NotFound(err)
} else { } else {
ctx.Error(500, "GetCommentByID", err) ctx.Error(500, "GetCommentByID", err)
} }
@ -361,7 +361,7 @@ func deleteIssueComment(ctx *context.APIContext) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrCommentNotExist(err) { if models.IsErrCommentNotExist(err) {
ctx.Error(404, "GetCommentByID", err) ctx.NotFound(err)
} else { } else {
ctx.Error(500, "GetCommentByID", err) ctx.Error(500, "GetCommentByID", err)
} }

@ -44,7 +44,7 @@ func ListIssueLabels(ctx *context.APIContext) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -99,7 +99,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -171,7 +171,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -237,7 +237,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -303,7 +303,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }

@ -47,13 +47,13 @@ func ListTrackedTimes(ctx *context.APIContext) {
// "200": // "200":
// "$ref": "#/responses/TrackedTimeList" // "$ref": "#/responses/TrackedTimeList"
if !ctx.Repo.Repository.IsTimetrackerEnabled() { if !ctx.Repo.Repository.IsTimetrackerEnabled() {
ctx.Error(404, "IsTimetrackerEnabled", "Timetracker is diabled") ctx.NotFound("Timetracker is disabled")
return return
} }
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Error(404, "GetIssueByIndex", err) ctx.NotFound(err)
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -109,7 +109,7 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { if models.IsErrIssueNotExist(err) {
ctx.Error(404, "GetIssueByIndex", err) ctx.NotFound(err)
} else { } else {
ctx.Error(500, "GetIssueByIndex", err) ctx.Error(500, "GetIssueByIndex", err)
} }
@ -165,14 +165,14 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
user, err := models.GetUserByName(ctx.Params(":timetrackingusername")) user, err := models.GetUserByName(ctx.Params(":timetrackingusername"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404, "GetUserByName", err) ctx.NotFound(err)
} else { } else {
ctx.Error(500, "GetUserByName", err) ctx.Error(500, "GetUserByName", err)
} }
return return
} }
if user == nil { if user == nil {
ctx.Status(404) ctx.NotFound()
return return
} }
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{ trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{

@ -125,7 +125,7 @@ func GetDeployKey(ctx *context.APIContext) {
key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id")) key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrDeployKeyNotExist(err) { if models.IsErrDeployKeyNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetDeployKeyByID", err) ctx.Error(500, "GetDeployKeyByID", err)
} }

@ -87,7 +87,7 @@ func GetLabel(ctx *context.APIContext) {
} }
if err != nil { if err != nil {
if models.IsErrLabelNotExist(err) { if models.IsErrLabelNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetLabelByRepoID", err) ctx.Error(500, "GetLabelByRepoID", err)
} }
@ -172,7 +172,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrLabelNotExist(err) { if models.IsErrLabelNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetLabelByRepoID", err) ctx.Error(500, "GetLabelByRepoID", err)
} }

@ -78,7 +78,7 @@ func GetMilestone(ctx *context.APIContext) {
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrMilestoneNotExist(err) { if models.IsErrMilestoneNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetMilestoneByRepoID", err) ctx.Error(500, "GetMilestoneByRepoID", err)
} }
@ -169,7 +169,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrMilestoneNotExist(err) { if models.IsErrMilestoneNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetMilestoneByRepoID", err) ctx.Error(500, "GetMilestoneByRepoID", err)
} }

@ -136,7 +136,7 @@ func GetPullRequest(ctx *context.APIContext) {
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrPullRequestNotExist(err) { if models.IsErrPullRequestNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetPullRequestByIndex", err) ctx.Error(500, "GetPullRequestByIndex", err)
} }
@ -231,7 +231,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID) milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID)
if err != nil { if err != nil {
if models.IsErrMilestoneNotExist(err) { if models.IsErrMilestoneNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetMilestoneByRepoID", err) ctx.Error(500, "GetMilestoneByRepoID", err)
} }
@ -341,7 +341,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrPullRequestNotExist(err) { if models.IsErrPullRequestNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetPullRequestByIndex", err) ctx.Error(500, "GetPullRequestByIndex", err)
} }
@ -438,7 +438,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
pr, err = models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pr.Index) pr, err = models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pr.Index)
if err != nil { if err != nil {
if models.IsErrPullRequestNotExist(err) { if models.IsErrPullRequestNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetPullRequestByIndex", err) ctx.Error(500, "GetPullRequestByIndex", err)
} }
@ -481,7 +481,7 @@ func IsPullRequestMerged(ctx *context.APIContext) {
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrPullRequestNotExist(err) { if models.IsErrPullRequestNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetPullRequestByIndex", err) ctx.Error(500, "GetPullRequestByIndex", err)
} }
@ -491,7 +491,7 @@ func IsPullRequestMerged(ctx *context.APIContext) {
if pr.HasMerged { if pr.HasMerged {
ctx.Status(204) ctx.Status(204)
} }
ctx.Status(404) ctx.NotFound()
} }
// MergePullRequest merges a PR given an index // MergePullRequest merges a PR given an index
@ -554,7 +554,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
} }
if pr.Issue.IsClosed { if pr.Issue.IsClosed {
ctx.Status(404) ctx.NotFound()
return return
} }
@ -634,7 +634,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headBranch = headInfos[1] headBranch = headInfos[1]
} else { } else {
ctx.Status(404) ctx.NotFound()
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
@ -643,7 +643,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
log.Info("Repo path: %s", ctx.Repo.GitRepo.Path) log.Info("Repo path: %s", ctx.Repo.GitRepo.Path)
// Check if base branch is valid. // Check if base branch is valid.
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) { if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
ctx.Status(404) ctx.NotFound()
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
@ -651,7 +651,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headRepo, has := models.HasForkedRepo(headUser.ID, baseRepo.ID) headRepo, has := models.HasForkedRepo(headUser.ID, baseRepo.ID)
if !has && !isSameRepo { if !has && !isSameRepo {
log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
ctx.Status(404) ctx.NotFound()
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
@ -674,13 +674,13 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
} }
if !perm.CanReadIssuesOrPulls(true) { if !perm.CanReadIssuesOrPulls(true) {
log.Trace("ParseCompareInfo[%d]: cannot create/read pull requests", baseRepo.ID) log.Trace("ParseCompareInfo[%d]: cannot create/read pull requests", baseRepo.ID)
ctx.Status(404) ctx.NotFound()
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }
// Check if head branch is valid. // Check if head branch is valid.
if !headGitRepo.IsBranchExist(headBranch) { if !headGitRepo.IsBranchExist(headBranch) {
ctx.Status(404) ctx.NotFound()
return nil, nil, nil, nil, "", "" return nil, nil, nil, nil, "", ""
} }

@ -46,7 +46,7 @@ func GetRelease(ctx *context.APIContext) {
return return
} }
if release.RepoID != ctx.Repo.Repository.ID { if release.RepoID != ctx.Repo.Repository.ID {
ctx.Status(404) ctx.NotFound()
return return
} }
if err := release.LoadAttributes(); err != nil { if err := release.LoadAttributes(); err != nil {
@ -241,7 +241,7 @@ func EditRelease(ctx *context.APIContext, form api.EditReleaseOption) {
} }
if err != nil && models.IsErrReleaseNotExist(err) || if err != nil && models.IsErrReleaseNotExist(err) ||
rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID { rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID {
ctx.Status(404) ctx.NotFound()
return return
} }
@ -313,7 +313,7 @@ func DeleteRelease(ctx *context.APIContext) {
} }
if err != nil && models.IsErrReleaseNotExist(err) || if err != nil && models.IsErrReleaseNotExist(err) ||
rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID { rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID {
ctx.Status(404) ctx.NotFound()
return return
} }
if err := models.DeleteReleaseByID(id, ctx.User, false); err != nil { if err := models.DeleteReleaseByID(id, ctx.User, false); err != nil {

@ -57,7 +57,7 @@ func GetReleaseAttachment(ctx *context.APIContext) {
return return
} }
if attach.ReleaseID != releaseID { if attach.ReleaseID != releaseID {
ctx.Status(404) ctx.NotFound()
return return
} }
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests // FIXME Should prove the existence of the given repo, but results in unnecessary database requests
@ -98,7 +98,7 @@ func ListReleaseAttachments(ctx *context.APIContext) {
return return
} }
if release.RepoID != ctx.Repo.Repository.ID { if release.RepoID != ctx.Repo.Repository.ID {
ctx.Status(404) ctx.NotFound()
return return
} }
if err := release.LoadAttributes(); err != nil { if err := release.LoadAttributes(); err != nil {
@ -150,7 +150,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
// Check if attachments are enabled // Check if attachments are enabled
if !setting.AttachmentEnabled { if !setting.AttachmentEnabled {
ctx.Error(404, "AttachmentEnabled", errors.New("attachment is not enabled")) ctx.NotFound("Attachment is not enabled")
return return
} }
@ -262,7 +262,7 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio
return return
} }
if attach.ReleaseID != releaseID { if attach.ReleaseID != releaseID {
ctx.Status(404) ctx.NotFound()
return return
} }
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests // FIXME Should prove the existence of the given repo, but results in unnecessary database requests
@ -319,7 +319,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
return return
} }
if attach.ReleaseID != releaseID { if attach.ReleaseID != releaseID {
ctx.Status(404) ctx.NotFound()
return return
} }
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests // FIXME Should prove the existence of the given repo, but results in unnecessary database requests

@ -472,7 +472,7 @@ func GetByID(ctx *context.APIContext) {
repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id")) repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetRepositoryByID", err) ctx.Error(500, "GetRepositoryByID", err)
} }
@ -484,7 +484,7 @@ func GetByID(ctx *context.APIContext) {
ctx.Error(500, "AccessLevel", err) ctx.Error(500, "AccessLevel", err)
return return
} else if !perm.HasAccess() { } else if !perm.HasAccess() {
ctx.Status(404) ctx.NotFound()
return return
} }
ctx.JSON(200, repo.APIFormat(perm.AccessMode)) ctx.JSON(200, repo.APIFormat(perm.AccessMode))

@ -112,7 +112,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
tokenID := ctx.ParamsInt64(":id") tokenID := ctx.ParamsInt64(":id")
if err := models.DeleteAccessTokenByID(tokenID, ctx.User.ID); err != nil { if err := models.DeleteAccessTokenByID(tokenID, ctx.User.ID); err != nil {
if models.IsErrAccessTokenNotExist(err) { if models.IsErrAccessTokenNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "DeleteAccessTokenByID", err) ctx.Error(500, "DeleteAccessTokenByID", err)
} }

@ -113,7 +113,7 @@ func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64)
if u.IsFollowing(followID) { if u.IsFollowing(followID) {
ctx.Status(204) ctx.Status(204)
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
} }

@ -90,7 +90,7 @@ func GetGPGKey(ctx *context.APIContext) {
key, err := models.GetGPGKeyByID(ctx.ParamsInt64(":id")) key, err := models.GetGPGKeyByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrGPGKeyNotExist(err) { if models.IsErrGPGKeyNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetGPGKeyByID", err) ctx.Error(500, "GetGPGKeyByID", err)
} }

@ -42,7 +42,7 @@ func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
user, err := models.GetUserByName(ctx.Params(name)) user, err := models.GetUserByName(ctx.Params(name))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetUserByName", err) ctx.Error(500, "GetUserByName", err)
} }
@ -165,7 +165,7 @@ func GetPublicKey(ctx *context.APIContext) {
key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id")) key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrKeyNotExist(err) { if models.IsErrKeyNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetPublicKeyByID", err) ctx.Error(500, "GetPublicKeyByID", err)
} }
@ -246,7 +246,7 @@ func DeletePublicKey(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil { if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
if models.IsErrKeyNotExist(err) { if models.IsErrKeyNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else if models.IsErrKeyAccessDenied(err) { } else if models.IsErrKeyAccessDenied(err) {
ctx.Error(403, "", "You do not have access to this key") ctx.Error(403, "", "You do not have access to this key")
} else { } else {

@ -96,7 +96,7 @@ func IsStarring(ctx *context.APIContext) {
if models.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) { if models.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) {
ctx.Status(204) ctx.Status(204)
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
} }

@ -109,7 +109,7 @@ func GetInfo(ctx *context.APIContext) {
u, err := models.GetUserByName(ctx.Params(":username")) u, err := models.GetUserByName(ctx.Params(":username"))
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetUserByName", err) ctx.Error(500, "GetUserByName", err)
} }

@ -103,7 +103,7 @@ func IsWatching(ctx *context.APIContext) {
RepositoryURL: repositoryURL(ctx.Repo.Repository), RepositoryURL: repositoryURL(ctx.Repo.Repository),
}) })
} else { } else {
ctx.Status(404) ctx.NotFound()
} }
} }

@ -24,7 +24,7 @@ func GetOrgHook(ctx *context.APIContext, orgID, hookID int64) (*models.Webhook,
w, err := models.GetWebhookByOrgID(orgID, hookID) w, err := models.GetWebhookByOrgID(orgID, hookID)
if err != nil { if err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetWebhookByOrgID", err) ctx.Error(500, "GetWebhookByOrgID", err)
} }
@ -39,7 +39,7 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*models.Webhook
w, err := models.GetWebhookByRepoID(repoID, hookID) w, err := models.GetWebhookByRepoID(repoID, hookID)
if err != nil { if err != nil {
if models.IsErrWebhookNotExist(err) { if models.IsErrWebhookNotExist(err) {
ctx.Status(404) ctx.NotFound()
} else { } else {
ctx.Error(500, "GetWebhookByID", err) ctx.Error(500, "GetWebhookByID", err)
} }

Loading…
Cancel
Save