diff options
author | John Olheiser <42128690+jolheiser@users.noreply.github.com> | 2019-03-18 21:29:43 -0500 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-03-18 22:29:43 -0400 |
commit | cac9e6e7605184f5679b1ebfbe5b5805191d9a53 (patch) | |
tree | 459a00974c8eff4f9cad8843b16d2a1f476c5912 /routers/api/v1/repo | |
parent | d10a668ffc4ed2a81a8a62ee78f0885ede713ddd (diff) | |
download | gitea-cac9e6e7605184f5679b1ebfbe5b5805191d9a53.tar.gz gitea-cac9e6e7605184f5679b1ebfbe5b5805191d9a53.zip |
Updates to API 404 responses (#6077)
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r-- | routers/api/v1/repo/branch.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/collaborators.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/file.go | 8 | ||||
-rw-r--r-- | routers/api/v1/repo/git_ref.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/hook.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 10 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_comment.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_label.go | 10 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_tracked_time.go | 10 | ||||
-rw-r--r-- | routers/api/v1/repo/key.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/label.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/milestone.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 24 | ||||
-rw-r--r-- | routers/api/v1/repo/release.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/release_attachment.go | 10 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 4 |
16 files changed, 53 insertions, 53 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index e8c965a814..e20eef6139 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -42,13 +42,13 @@ func GetBranch(ctx *context.APIContext) { // if TreePath != "", then URL contained extra slashes // (i.e. "master/subbranch" instead of "master"), so branch does // not exist - ctx.Status(404) + ctx.NotFound() return } branch, err := ctx.Repo.Repository.GetBranch(ctx.Repo.BranchName) if err != nil { if models.IsErrBranchNotExist(err) { - ctx.Error(404, "GetBranch", err) + ctx.NotFound(err) } else { ctx.Error(500, "GetBranch", err) } diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index 2f254f7103..be4a65f9c8 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -92,7 +92,7 @@ func IsCollaborator(ctx *context.APIContext) { if isColab { ctx.Status(204) } else { - ctx.Status(404) + ctx.NotFound() } } diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go index 762a0f25d9..929ed00d68 100644 --- a/routers/api/v1/repo/file.go +++ b/routers/api/v1/repo/file.go @@ -40,14 +40,14 @@ func GetRawFile(ctx *context.APIContext) { // 200: // description: success if ctx.Repo.Repository.IsEmpty { - ctx.Status(404) + ctx.NotFound() return } blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath) if err != nil { if git.IsErrNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetBlobByPath", err) } @@ -124,7 +124,7 @@ func GetEditorconfig(ctx *context.APIContext) { ec, err := ctx.Repo.GetEditorconfig() if err != nil { if git.IsErrNotExist(err) { - ctx.Error(404, "GetEditorconfig", err) + ctx.NotFound(err) } else { ctx.Error(500, "GetEditorconfig", err) } @@ -134,7 +134,7 @@ func GetEditorconfig(ctx *context.APIContext) { fileName := ctx.Params("filename") def := ec.GetDefinitionForFilename(fileName) if def == nil { - ctx.Error(404, "GetDefinitionForFilename", err) + ctx.NotFound(err) return } ctx.JSON(200, def) diff --git a/routers/api/v1/repo/git_ref.go b/routers/api/v1/repo/git_ref.go index 7d60b8e0e7..ffdfc57b1d 100644 --- a/routers/api/v1/repo/git_ref.go +++ b/routers/api/v1/repo/git_ref.go @@ -89,7 +89,7 @@ func getGitRefsInternal(ctx *context.APIContext, filter string) { } if len(refs) == 0 { - ctx.Status(404) + ctx.NotFound() return } diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go index 369603694f..f01049721e 100644 --- a/routers/api/v1/repo/hook.go +++ b/routers/api/v1/repo/hook.go @@ -239,7 +239,7 @@ func DeleteHook(ctx *context.APIContext) { // "$ref": "#/responses/notFound" if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil { if models.IsErrWebhookNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "DeleteWebhookByRepoID", err) } diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 27b3d93a75..08bc732530 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -146,7 +146,7 @@ func GetIssue(ctx *context.APIContext) { issue, err := models.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetIssueByIndex", err) } diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 3e6f04eb7a..fd085b66bc 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -268,7 +268,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { - ctx.Error(404, "GetCommentByID", err) + ctx.NotFound(err) } else { ctx.Error(500, "GetCommentByID", err) } @@ -361,7 +361,7 @@ func deleteIssueComment(ctx *context.APIContext) { comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { - ctx.Error(404, "GetCommentByID", err) + ctx.NotFound(err) } else { ctx.Error(500, "GetCommentByID", err) } diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go index d496f5bde6..4c8ca8d523 100644 --- a/routers/api/v1/repo/issue_label.go +++ b/routers/api/v1/repo/issue_label.go @@ -44,7 +44,7 @@ func ListIssueLabels(ctx *context.APIContext) { issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetIssueByIndex", err) } diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 6c29b11b4b..d2ddb0e0c8 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -47,13 +47,13 @@ func ListTrackedTimes(ctx *context.APIContext) { // "200": // "$ref": "#/responses/TrackedTimeList" if !ctx.Repo.Repository.IsTimetrackerEnabled() { - ctx.Error(404, "IsTimetrackerEnabled", "Timetracker is diabled") + ctx.NotFound("Timetracker is disabled") return } issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Error(404, "GetIssueByIndex", err) + ctx.NotFound(err) } else { 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")) if err != nil { if models.IsErrIssueNotExist(err) { - ctx.Error(404, "GetIssueByIndex", err) + ctx.NotFound(err) } else { ctx.Error(500, "GetIssueByIndex", err) } @@ -165,14 +165,14 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { user, err := models.GetUserByName(ctx.Params(":timetrackingusername")) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Error(404, "GetUserByName", err) + ctx.NotFound(err) } else { ctx.Error(500, "GetUserByName", err) } return } if user == nil { - ctx.Status(404) + ctx.NotFound() return } trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{ diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go index 2ee1ce0098..e26ce8cf50 100644 --- a/routers/api/v1/repo/key.go +++ b/routers/api/v1/repo/key.go @@ -125,7 +125,7 @@ func GetDeployKey(ctx *context.APIContext) { key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id")) if err != nil { if models.IsErrDeployKeyNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetDeployKeyByID", err) } diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index df7a370041..f61751f3ab 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -87,7 +87,7 @@ func GetLabel(ctx *context.APIContext) { } if err != nil { if models.IsErrLabelNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrLabelNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetLabelByRepoID", err) } diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 88386c3efa..a76f601a21 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -78,7 +78,7 @@ func GetMilestone(ctx *context.APIContext) { milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrMilestoneNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrMilestoneNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetMilestoneByRepoID", err) } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 9d3d9443f7..156ca83a19 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -136,7 +136,7 @@ func GetPullRequest(ctx *context.APIContext) { pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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) if err != nil { if models.IsErrMilestoneNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrPullRequestNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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) if err != nil { if models.IsErrPullRequestNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { 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")) if err != nil { if models.IsErrPullRequestNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetPullRequestByIndex", err) } @@ -491,7 +491,7 @@ func IsPullRequestMerged(ctx *context.APIContext) { if pr.HasMerged { ctx.Status(204) } - ctx.Status(404) + ctx.NotFound() } // MergePullRequest merges a PR given an index @@ -554,7 +554,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { } if pr.Issue.IsClosed { - ctx.Status(404) + ctx.NotFound() return } @@ -634,7 +634,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) headBranch = headInfos[1] } else { - ctx.Status(404) + ctx.NotFound() 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) // Check if base branch is valid. if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) { - ctx.Status(404) + ctx.NotFound() 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) if !has && !isSameRepo { log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) - ctx.Status(404) + ctx.NotFound() return nil, nil, nil, nil, "", "" } @@ -674,13 +674,13 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } if !perm.CanReadIssuesOrPulls(true) { log.Trace("ParseCompareInfo[%d]: cannot create/read pull requests", baseRepo.ID) - ctx.Status(404) + ctx.NotFound() return nil, nil, nil, nil, "", "" } // Check if head branch is valid. if !headGitRepo.IsBranchExist(headBranch) { - ctx.Status(404) + ctx.NotFound() return nil, nil, nil, nil, "", "" } diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index e622acb30c..1b5b19666c 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -46,7 +46,7 @@ func GetRelease(ctx *context.APIContext) { return } if release.RepoID != ctx.Repo.Repository.ID { - ctx.Status(404) + ctx.NotFound() return } if err := release.LoadAttributes(); err != nil { @@ -241,7 +241,7 @@ func EditRelease(ctx *context.APIContext, form api.EditReleaseOption) { } if err != nil && models.IsErrReleaseNotExist(err) || rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID { - ctx.Status(404) + ctx.NotFound() return } @@ -313,7 +313,7 @@ func DeleteRelease(ctx *context.APIContext) { } if err != nil && models.IsErrReleaseNotExist(err) || rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID { - ctx.Status(404) + ctx.NotFound() return } if err := models.DeleteReleaseByID(id, ctx.User, false); err != nil { diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index ea2be719f3..50107dd44e 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -57,7 +57,7 @@ func GetReleaseAttachment(ctx *context.APIContext) { return } if attach.ReleaseID != releaseID { - ctx.Status(404) + ctx.NotFound() return } // 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 } if release.RepoID != ctx.Repo.Repository.ID { - ctx.Status(404) + ctx.NotFound() return } if err := release.LoadAttributes(); err != nil { @@ -150,7 +150,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) { // Check if attachments are enabled if !setting.AttachmentEnabled { - ctx.Error(404, "AttachmentEnabled", errors.New("attachment is not enabled")) + ctx.NotFound("Attachment is not enabled") return } @@ -262,7 +262,7 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio return } if attach.ReleaseID != releaseID { - ctx.Status(404) + ctx.NotFound() return } // 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 } if attach.ReleaseID != releaseID { - ctx.Status(404) + ctx.NotFound() return } // FIXME Should prove the existence of the given repo, but results in unnecessary database requests diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index e5922e77dc..36e8380f44 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -472,7 +472,7 @@ func GetByID(ctx *context.APIContext) { repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id")) if err != nil { if models.IsErrRepoNotExist(err) { - ctx.Status(404) + ctx.NotFound() } else { ctx.Error(500, "GetRepositoryByID", err) } @@ -484,7 +484,7 @@ func GetByID(ctx *context.APIContext) { ctx.Error(500, "AccessLevel", err) return } else if !perm.HasAccess() { - ctx.Status(404) + ctx.NotFound() return } ctx.JSON(200, repo.APIFormat(perm.AccessMode)) |