mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
[refactor] replace int with httpStatusCodes (#15282)
* replace "200" (int) with "http.StatusOK" (const) * ctx.Error & ctx.HTML * ctx.JSON Part1 * ctx.JSON Part2 * ctx.JSON Part3
This commit is contained in:
@@ -8,6 +8,7 @@ package repo
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -85,7 +86,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
|
||||
|
||||
// Check ownership of organization.
|
||||
if !org.IsOrganization() {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return nil
|
||||
}
|
||||
if !ctx.User.IsAdmin {
|
||||
@@ -94,7 +95,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
|
||||
ctx.ServerError("CanCreateOrgRepo", err)
|
||||
return nil
|
||||
} else if !canCreate {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
@@ -149,7 +150,7 @@ func Create(ctx *context.Context) {
|
||||
ctx.Data["CanCreateRepo"] = ctx.User.CanCreateRepo()
|
||||
ctx.Data["MaxCreationLimit"] = ctx.User.MaxCreationLimit()
|
||||
|
||||
ctx.HTML(200, tplCreate)
|
||||
ctx.HTML(http.StatusOK, tplCreate)
|
||||
}
|
||||
|
||||
func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
|
||||
@@ -199,7 +200,7 @@ func CreatePost(ctx *context.Context) {
|
||||
ctx.Data["ContextUser"] = ctxUser
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplCreate)
|
||||
ctx.HTML(http.StatusOK, tplCreate)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -281,7 +282,7 @@ func Action(ctx *context.Context) {
|
||||
err = acceptOrRejectRepoTransfer(ctx, false)
|
||||
case "desc": // FIXME: this is not used
|
||||
if !ctx.Repo.IsOwner() {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -339,7 +340,7 @@ func RedirectDownload(ctx *context.Context) {
|
||||
releases, err := models.GetReleasesByRepoIDAndNames(models.DefaultDBContext(), curRepo.ID, tagNames)
|
||||
if err != nil {
|
||||
if models.IsErrAttachmentNotExist(err) {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
ctx.ServerError("RedirectDownload", err)
|
||||
@@ -349,7 +350,7 @@ func RedirectDownload(ctx *context.Context) {
|
||||
release := releases[0]
|
||||
att, err := models.GetAttachmentByReleaseIDFileName(release.ID, fileName)
|
||||
if err != nil {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if att != nil {
|
||||
@@ -357,7 +358,7 @@ func RedirectDownload(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
}
|
||||
|
||||
// Download an archive of a repository
|
||||
@@ -366,7 +367,7 @@ func Download(ctx *context.Context) {
|
||||
aReq := archiver_service.DeriveRequestFrom(ctx, uri)
|
||||
|
||||
if aReq == nil {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -380,7 +381,7 @@ func Download(ctx *context.Context) {
|
||||
if complete {
|
||||
ctx.ServeFile(aReq.GetArchivePath(), downloadName)
|
||||
} else {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +393,7 @@ func InitiateDownload(ctx *context.Context) {
|
||||
aReq := archiver_service.DeriveRequestFrom(ctx, uri)
|
||||
|
||||
if aReq == nil {
|
||||
ctx.Error(404)
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -402,7 +403,7 @@ func InitiateDownload(ctx *context.Context) {
|
||||
complete, _ = aReq.TimedWaitForCompletion(ctx, 2*time.Second)
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"complete": complete,
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user