summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorMorgan Bazalgette <git@howl.moe>2018-01-10 22:34:17 +0100
committerLauris BH <lauris@nix.lv>2018-01-10 23:34:17 +0200
commit65861900cda3bb6d9e2aa80b808b0000383c04b3 (patch)
tree8569d93b6ef092b30b35a4d4da906c6b6950e2ee /routers/api
parent45c264f681e3f7e1a22a191029836a690959aac3 (diff)
downloadgitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.tar.gz
gitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.zip
Handle refactor (#3339)
* Replace all ctx.Handle with ctx.ServerError or ctx.NotFound * Change Handle(403) to NotFound, avoid using macaron's NotFound
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/repo/fork.go2
-rw-r--r--routers/api/v1/repo/label.go2
-rw-r--r--routers/api/v1/repo/milestone.go2
-rw-r--r--routers/api/v1/repo/pull.go8
-rw-r--r--routers/api/v1/repo/release.go4
-rw-r--r--routers/api/v1/repo/repo.go2
6 files changed, 10 insertions, 10 deletions
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index ec1b37b91a..694d7a9471 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -91,7 +91,7 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) {
}
isMember, err := org.IsOrgMember(ctx.User.ID)
if err != nil {
- ctx.Handle(500, "IsOrgMember", err)
+ ctx.ServerError("IsOrgMember", err)
return
} else if !isMember {
ctx.Status(403)
diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go
index cb724c7182..b9401cef68 100644
--- a/routers/api/v1/repo/label.go
+++ b/routers/api/v1/repo/label.go
@@ -193,7 +193,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
label.Color = *form.Color
}
if err := models.UpdateLabel(label); err != nil {
- ctx.Handle(500, "UpdateLabel", err)
+ ctx.ServerError("UpdateLabel", err)
return
}
ctx.JSON(200, label.APIFormat())
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index 29bab67ac5..53edd3230c 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -180,7 +180,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
}
if err := models.UpdateMilestone(milestone); err != nil {
- ctx.Handle(500, "UpdateMilestone", err)
+ ctx.ServerError("UpdateMilestone", err)
return
}
ctx.JSON(200, milestone.APIFormat())
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 7e011219be..742c0bccf9 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -465,7 +465,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrPullRequestNotExist(err) {
- ctx.Handle(404, "GetPullRequestByIndex", err)
+ ctx.NotFound("GetPullRequestByIndex", err)
} else {
ctx.Error(500, "GetPullRequestByIndex", err)
}
@@ -473,7 +473,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
}
if err = pr.GetHeadRepo(); err != nil {
- ctx.Handle(500, "GetHeadRepo", err)
+ ctx.ServerError("GetHeadRepo", err)
return
}
@@ -560,9 +560,9 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headUser, err = models.GetUserByName(headInfos[0])
if err != nil {
if models.IsErrUserNotExist(err) {
- ctx.Handle(404, "GetUserByName", nil)
+ ctx.NotFound("GetUserByName", nil)
} else {
- ctx.Handle(500, "GetUserByName", err)
+ ctx.ServerError("GetUserByName", err)
}
return nil, nil, nil, nil, "", ""
}
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index 17cddc5652..f5b529ac6a 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -132,7 +132,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName)
if err != nil {
if !models.IsErrReleaseNotExist(err) {
- ctx.Handle(500, "GetRelease", err)
+ ctx.ServerError("GetRelease", err)
return
}
rel = &models.Release{
@@ -169,7 +169,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
rel.IsTag = false
if err = models.UpdateRelease(ctx.Repo.GitRepo, rel, nil); err != nil {
- ctx.Handle(500, "UpdateRelease", err)
+ ctx.ServerError("UpdateRelease", err)
return
}
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index c9c7aa805d..b85ffd8d2f 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -258,7 +258,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
isOwner, err := org.IsOwnedBy(ctx.User.ID)
if err != nil {
- ctx.Handle(500, "IsOwnedBy", err)
+ ctx.ServerError("IsOwnedBy", err)
return
} else if !isOwner {
ctx.Error(403, "", "Given user is not owner of organization.")