Skip to content

Commit b1ff386

Browse files
committed
use numbers and not http.Status___ enum
1 parent e2fc0a0 commit b1ff386

File tree

14 files changed

+82
-96
lines changed

14 files changed

+82
-96
lines changed

routers/api/v1/misc/markdown.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package misc
66

77
import (
8-
"net/http"
98
"strings"
109

1110
"code.gitea.io/gitea/modules/context"
@@ -65,20 +64,20 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
6564
if form.Wiki {
6665
_, err := ctx.Write([]byte(markdown.RenderWiki(md, urlPrefix, meta)))
6766
if err != nil {
68-
ctx.Error(http.StatusInternalServerError, "", err)
67+
ctx.Error(500, "", err)
6968
return
7069
}
7170
} else {
7271
_, err := ctx.Write(markdown.Render(md, urlPrefix, meta))
7372
if err != nil {
74-
ctx.Error(http.StatusInternalServerError, "", err)
73+
ctx.Error(500, "", err)
7574
return
7675
}
7776
}
7877
default:
7978
_, err := ctx.Write(markdown.RenderRaw([]byte(form.Text), "", false))
8079
if err != nil {
81-
ctx.Error(http.StatusInternalServerError, "", err)
80+
ctx.Error(500, "", err)
8281
return
8382
}
8483
}
@@ -112,7 +111,7 @@ func MarkdownRaw(ctx *context.APIContext) {
112111
}
113112
_, err = ctx.Write(markdown.RenderRaw(body, "", false))
114113
if err != nil {
115-
ctx.Error(http.StatusInternalServerError, "", err)
114+
ctx.Error(500, "", err)
116115
return
117116
}
118117
}

routers/api/v1/misc/markdown_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package misc
22

33
import (
44
"io/ioutil"
5-
"net/http"
65
"net/http/httptest"
76
"net/url"
87
"strings"

routers/api/v1/misc/signing.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package misc
22

33
import (
44
"fmt"
5-
"net/http"
65

76
"code.gitea.io/gitea/models"
87
"code.gitea.io/gitea/modules/context"
@@ -57,6 +56,6 @@ func SigningKey(ctx *context.Context) {
5756
_, err = ctx.Write([]byte(content))
5857
if err != nil {
5958
log.Error("Error writing key content %v", err)
60-
ctx.Error(http.StatusInternalServerError, fmt.Sprintf("%v", err))
59+
ctx.Error(500, fmt.Sprintf("%v", err))
6160
}
6261
}

routers/api/v1/repo/blob.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package repo
66

77
import (
8-
"net/http"
98

109
"code.gitea.io/gitea/modules/context"
1110
"code.gitea.io/gitea/modules/repofiles"
@@ -40,12 +39,12 @@ func GetBlob(ctx *context.APIContext) {
4039

4140
sha := ctx.Params("sha")
4241
if len(sha) == 0 {
43-
ctx.Error(http.StatusBadRequest, "", "sha not provided")
42+
ctx.Error(400, "", "sha not provided")
4443
return
4544
}
4645
if blob, err := repofiles.GetBlobBySHA(ctx.Repo.Repository, sha); err != nil {
47-
ctx.Error(http.StatusBadRequest, "", err)
46+
ctx.Error(400, "", err)
4847
} else {
49-
ctx.JSON(http.StatusOK, blob)
48+
ctx.JSON(200, blob)
5049
}
5150
}

routers/api/v1/repo/file.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package repo
77

88
import (
99
"encoding/base64"
10-
"net/http"
1110

1211
"code.gitea.io/gitea/models"
1312
"code.gitea.io/gitea/modules/context"
@@ -53,12 +52,12 @@ func GetRawFile(ctx *context.APIContext) {
5352
if git.IsErrNotExist(err) {
5453
ctx.NotFound()
5554
} else {
56-
ctx.Error(http.StatusInternalServerError, "GetBlobByPath", err)
55+
ctx.Error(500, "GetBlobByPath", err)
5756
}
5857
return
5958
}
6059
if err = repo.ServeBlob(ctx.Context, blob); err != nil {
61-
ctx.Error(http.StatusInternalServerError, "ServeBlob", err)
60+
ctx.Error(500, "ServeBlob", err)
6261
}
6362
}
6463

@@ -91,7 +90,7 @@ func GetArchive(ctx *context.APIContext) {
9190
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
9291
gitRepo, err := git.OpenRepository(repoPath)
9392
if err != nil {
94-
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
93+
ctx.Error(500, "OpenRepository", err)
9594
return
9695
}
9796
ctx.Repo.GitRepo = gitRepo
@@ -131,7 +130,7 @@ func GetEditorconfig(ctx *context.APIContext) {
131130
if git.IsErrNotExist(err) {
132131
ctx.NotFound(err)
133132
} else {
134-
ctx.Error(http.StatusInternalServerError, "GetEditorconfig", err)
133+
ctx.Error(500, "GetEditorconfig", err)
135134
}
136135
return
137136
}
@@ -142,7 +141,7 @@ func GetEditorconfig(ctx *context.APIContext) {
142141
ctx.NotFound(err)
143142
return
144143
}
145-
ctx.JSON(http.StatusOK, def)
144+
ctx.JSON(200, def)
146145
}
147146

148147
// CanWriteFiles returns true if repository is editable and user has proper access level.
@@ -211,9 +210,9 @@ func CreateFile(ctx *context.APIContext, apiOpts api.CreateFileOptions) {
211210
}
212211

213212
if fileResponse, err := createOrUpdateFile(ctx, opts); err != nil {
214-
ctx.Error(http.StatusInternalServerError, "CreateFile", err)
213+
ctx.Error(500, "CreateFile", err)
215214
} else {
216-
ctx.JSON(http.StatusCreated, fileResponse)
215+
ctx.JSON(201, fileResponse)
217216
}
218217
}
219218

@@ -275,9 +274,9 @@ func UpdateFile(ctx *context.APIContext, apiOpts api.UpdateFileOptions) {
275274
}
276275

277276
if fileResponse, err := createOrUpdateFile(ctx, opts); err != nil {
278-
ctx.Error(http.StatusInternalServerError, "UpdateFile", err)
277+
ctx.Error(500, "UpdateFile", err)
279278
} else {
280-
ctx.JSON(http.StatusOK, fileResponse)
279+
ctx.JSON(200, fileResponse)
281280
}
282281
}
283282

@@ -333,7 +332,7 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
333332
// "200":
334333
// "$ref": "#/responses/FileDeleteResponse"
335334
if !CanWriteFiles(ctx.Repo) {
336-
ctx.Error(http.StatusInternalServerError, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{
335+
ctx.Error(500, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{
337336
UserID: ctx.User.ID,
338337
RepoName: ctx.Repo.Repository.LowerName,
339338
})
@@ -361,9 +360,9 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
361360
}
362361

363362
if fileResponse, err := repofiles.DeleteRepoFile(ctx.Repo.Repository, ctx.User, opts); err != nil {
364-
ctx.Error(http.StatusInternalServerError, "DeleteFile", err)
363+
ctx.Error(500, "DeleteFile", err)
365364
} else {
366-
ctx.JSON(http.StatusOK, fileResponse)
365+
ctx.JSON(200, fileResponse)
367366
}
368367
}
369368

@@ -400,7 +399,7 @@ func GetContents(ctx *context.APIContext) {
400399
// "$ref": "#/responses/ContentsResponse"
401400

402401
if !CanReadFiles(ctx.Repo) {
403-
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
402+
ctx.Error(500, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
404403
UserID: ctx.User.ID,
405404
RepoName: ctx.Repo.Repository.LowerName,
406405
})
@@ -411,9 +410,9 @@ func GetContents(ctx *context.APIContext) {
411410
ref := ctx.QueryTrim("ref")
412411

413412
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
414-
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err)
413+
ctx.Error(500, "GetContentsOrList", err)
415414
} else {
416-
ctx.JSON(http.StatusOK, fileList)
415+
ctx.JSON(200, fileList)
417416
}
418417
}
419418

routers/api/v1/repo/hook_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package repo
66

77
import (
8-
"net/http"
98
"testing"
109

1110
"code.gitea.io/gitea/models"
@@ -24,7 +23,7 @@ func TestTestHook(t *testing.T) {
2423
test.LoadRepoCommit(t, ctx)
2524
test.LoadUser(t, ctx, 2)
2625
TestHook(&context.APIContext{Context: ctx, Org: nil})
27-
assert.EqualValues(t, http.StatusNoContent, ctx.Resp.Status())
26+
assert.EqualValues(t, 204, ctx.Resp.Status())
2827

2928
models.AssertExistsAndLoadBean(t, &models.HookTask{
3029
RepoID: 1,

routers/api/v1/repo/issue.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package repo
77

88
import (
99
"fmt"
10-
"net/http"
1110
"strings"
1211
"time"
1312

@@ -379,7 +378,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
379378
if form.Closed {
380379
if err := issue_service.ChangeStatus(issue, ctx.User, true); err != nil {
381380
if models.IsErrDependenciesLeft(err) {
382-
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
381+
ctx.Error(412, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
383382
return
384383
}
385384
ctx.Error(500, "ChangeStatus", err)
@@ -513,7 +512,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
513512
if form.State != nil {
514513
if err = issue_service.ChangeStatus(issue, ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
515514
if models.IsErrDependenciesLeft(err) {
516-
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
515+
ctx.Error(412, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
517516
return
518517
}
519518
ctx.Error(500, "ChangeStatus", err)

routers/api/v1/repo/pull.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package repo
66

77
import (
88
"fmt"
9-
"net/http"
109
"strings"
1110
"time"
1211

@@ -360,7 +359,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
360359

361360
err = pr.LoadIssue()
362361
if err != nil {
363-
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
362+
ctx.Error(500, "LoadIssue", err)
364363
return
365364
}
366365
issue := pr.Issue
@@ -443,7 +442,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
443442
if form.State != nil {
444443
if err = issue_service.ChangeStatus(issue, ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
445444
if models.IsErrDependenciesLeft(err) {
446-
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
445+
ctx.Error(412, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
447446
return
448447
}
449448
ctx.Error(500, "ChangeStatus", err)
@@ -561,7 +560,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
561560

562561
err = pr.LoadIssue()
563562
if err != nil {
564-
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
563+
ctx.Error(500, "LoadIssue", err)
565564
return
566565
}
567566
pr.Issue.Repo = ctx.Repo.Repository
@@ -620,15 +619,15 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
620619
return
621620
} else if models.IsErrMergeConflicts(err) {
622621
conflictError := err.(models.ErrMergeConflicts)
623-
ctx.JSON(http.StatusConflict, conflictError)
622+
ctx.JSON(409, conflictError)
624623
} else if models.IsErrRebaseConflicts(err) {
625624
conflictError := err.(models.ErrRebaseConflicts)
626-
ctx.JSON(http.StatusConflict, conflictError)
625+
ctx.JSON(409, conflictError)
627626
} else if models.IsErrMergeUnrelatedHistories(err) {
628627
conflictError := err.(models.ErrMergeUnrelatedHistories)
629-
ctx.JSON(http.StatusConflict, conflictError)
628+
ctx.JSON(409, conflictError)
630629
} else if models.IsErrMergePushOutOfDate(err) {
631-
ctx.Status(http.StatusConflict)
630+
ctx.Status(409)
632631
return
633632
}
634633
ctx.Error(500, "Merge", err)

0 commit comments

Comments
 (0)