aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
author赵智超 <1012112796@qq.com>2020-09-21 04:20:14 +0800
committerGitHub <noreply@github.com>2020-09-20 21:20:14 +0100
commitfec152155543e72f2e03885d431642887ce09d69 (patch)
tree6ba0d440eec9df315c8acf487918036717cf98f0 /routers/api/v1/repo
parente7ffc67ad5add193e90219a856935bf643b33fe1 (diff)
downloadgitea-fec152155543e72f2e03885d431642887ce09d69.tar.gz
gitea-fec152155543e72f2e03885d431642887ce09d69.zip
Not using "ctx.ServerError" in api (#12907)
This function will render a whole html page which is not useful for API. Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/commits.go18
-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/pull_review.go6
-rw-r--r--routers/api/v1/repo/release.go4
-rw-r--r--routers/api/v1/repo/repo.go2
8 files changed, 22 insertions, 22 deletions
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index 220bb0fd74..8c877285a8 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -63,7 +63,7 @@ func GetSingleCommit(ctx *context.APIContext) {
func getCommit(ctx *context.APIContext, identifier string) {
gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
if err != nil {
- ctx.ServerError("OpenRepository", err)
+ ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return
}
defer gitRepo.Close()
@@ -75,7 +75,7 @@ func getCommit(ctx *context.APIContext, identifier string) {
json, err := convert.ToCommit(ctx.Repo.Repository, commit, nil)
if err != nil {
- ctx.ServerError("toCommit", err)
+ ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
}
ctx.JSON(http.StatusOK, json)
@@ -129,7 +129,7 @@ func GetAllCommits(ctx *context.APIContext) {
gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
if err != nil {
- ctx.ServerError("OpenRepository", err)
+ ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return
}
defer gitRepo.Close()
@@ -150,20 +150,20 @@ func GetAllCommits(ctx *context.APIContext) {
// no sha supplied - use default branch
head, err := gitRepo.GetHEADBranch()
if err != nil {
- ctx.ServerError("GetHEADBranch", err)
+ ctx.Error(http.StatusInternalServerError, "GetHEADBranch", err)
return
}
baseCommit, err = gitRepo.GetBranchCommit(head.Name)
if err != nil {
- ctx.ServerError("GetCommit", err)
+ ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
}
} else {
// get commit specified by sha
baseCommit, err = gitRepo.GetCommit(sha)
if err != nil {
- ctx.ServerError("GetCommit", err)
+ ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
}
}
@@ -171,7 +171,7 @@ func GetAllCommits(ctx *context.APIContext) {
// Total commit count
commitsCountTotal, err := baseCommit.CommitsCount()
if err != nil {
- ctx.ServerError("GetCommitsCount", err)
+ ctx.Error(http.StatusInternalServerError, "GetCommitsCount", err)
return
}
@@ -180,7 +180,7 @@ func GetAllCommits(ctx *context.APIContext) {
// Query commits
commits, err := baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize)
if err != nil {
- ctx.ServerError("CommitsByRange", err)
+ ctx.Error(http.StatusInternalServerError, "CommitsByRange", err)
return
}
@@ -195,7 +195,7 @@ func GetAllCommits(ctx *context.APIContext) {
// Create json struct
apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, commit, userCache)
if err != nil {
- ctx.ServerError("toCommit", err)
+ ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
}
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 0dd961d7f0..e6f5f5e630 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -109,7 +109,7 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) {
}
isMember, err := org.IsOrgMember(ctx.User.ID)
if err != nil {
- ctx.ServerError("IsOrgMember", err)
+ ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
return
} else if !isMember {
ctx.Error(http.StatusForbidden, "isMemberNot", fmt.Sprintf("User is no Member of Organisation '%s'", org.Name))
diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go
index a293801c4f..fef6ebf07a 100644
--- a/routers/api/v1/repo/label.go
+++ b/routers/api/v1/repo/label.go
@@ -222,7 +222,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
label.Description = *form.Description
}
if err := models.UpdateLabel(label); err != nil {
- ctx.ServerError("UpdateLabel", err)
+ ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
return
}
ctx.JSON(http.StatusOK, convert.ToLabel(label))
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index 5a250dbd80..db86d0868f 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -215,7 +215,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
}
if err := models.UpdateMilestone(milestone, oldIsClosed); err != nil {
- ctx.ServerError("UpdateMilestone", err)
+ ctx.Error(http.StatusInternalServerError, "UpdateMilestone", err)
return
}
ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone))
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 126815839d..afbe7ddab0 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -725,7 +725,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
}
if err = pr.LoadHeadRepo(); err != nil {
- ctx.ServerError("LoadHeadRepo", err)
+ ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
return
}
@@ -885,7 +885,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
if models.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName")
} else {
- ctx.ServerError("GetUserByName", err)
+ ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
}
return nil, nil, nil, nil, "", ""
}
@@ -929,7 +929,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
permBase, err := models.GetUserRepoPermission(baseRepo, ctx.User)
if err != nil {
headGitRepo.Close()
- ctx.ServerError("GetUserRepoPermission", err)
+ ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(models.UnitTypeCode) {
@@ -948,7 +948,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
permHead, err := models.GetUserRepoPermission(headRepo, ctx.User)
if err != nil {
headGitRepo.Close()
- ctx.ServerError("GetUserRepoPermission", err)
+ ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return nil, nil, nil, nil, "", ""
}
if !permHead.CanRead(models.UnitTypeCode) {
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go
index 3f2cb011d8..86c084acd7 100644
--- a/routers/api/v1/repo/pull_review.go
+++ b/routers/api/v1/repo/pull_review.go
@@ -318,14 +318,14 @@ func CreatePullReview(ctx *context.APIContext, opts api.CreatePullReviewOptions)
if opts.CommitID == "" {
gitRepo, err := git.OpenRepository(pr.Issue.Repo.RepoPath())
if err != nil {
- ctx.ServerError("git.OpenRepository", err)
+ ctx.Error(http.StatusInternalServerError, "git.OpenRepository", err)
return
}
defer gitRepo.Close()
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
- ctx.ServerError("GetRefCommitID", err)
+ ctx.Error(http.StatusInternalServerError, "GetRefCommitID", err)
return
}
@@ -350,7 +350,7 @@ func CreatePullReview(ctx *context.APIContext, opts api.CreatePullReviewOptions)
0, // no reply
opts.CommitID,
); err != nil {
- ctx.ServerError("CreateCodeComment", err)
+ ctx.Error(http.StatusInternalServerError, "CreateCodeComment", err)
return
}
}
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index 752b5c76e0..e7cc1e8671 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -151,7 +151,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.ServerError("GetRelease", err)
+ ctx.Error(http.StatusInternalServerError, "GetRelease", err)
return
}
// If target is not provided use default branch
@@ -195,7 +195,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
rel.Publisher = ctx.User
if err = releaseservice.UpdateReleaseOrCreatReleaseFromTag(ctx.User, ctx.Repo.GitRepo, rel, nil, true); err != nil {
- ctx.ServerError("UpdateReleaseOrCreatReleaseFromTag", err)
+ ctx.Error(http.StatusInternalServerError, "UpdateReleaseOrCreatReleaseFromTag", err)
return
}
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index baf8110a19..b8a24e2532 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -373,7 +373,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
if !ctx.User.IsAdmin {
canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
if err != nil {
- ctx.ServerError("CanCreateOrgRepo", err)
+ ctx.Error(http.StatusInternalServerError, "CanCreateOrgRepo", err)
return
} else if !canCreate {
ctx.Error(http.StatusForbidden, "", "Given user is not allowed to create repository in organization.")