1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 10:18:38 +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:
6543
2021-04-05 17:30:52 +02:00
committed by GitHub
parent e9fba18a26
commit 16dea6cebd
64 changed files with 504 additions and 441 deletions

View File

@@ -5,6 +5,7 @@
package repo
import (
"net/http"
"strings"
"code.gitea.io/gitea/models"
@@ -15,7 +16,7 @@ import (
// TopicsPost response for creating repository
func TopicsPost(ctx *context.Context) {
if ctx.User == nil {
ctx.JSON(403, map[string]interface{}{
ctx.JSON(http.StatusForbidden, map[string]interface{}{
"message": "Only owners could change the topics.",
})
return
@@ -30,7 +31,7 @@ func TopicsPost(ctx *context.Context) {
validTopics, invalidTopics := models.SanitizeAndValidateTopics(topics)
if len(validTopics) > 25 {
ctx.JSON(422, map[string]interface{}{
ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{
"invalidTopics": nil,
"message": ctx.Tr("repo.topic.count_prompt"),
})
@@ -38,7 +39,7 @@ func TopicsPost(ctx *context.Context) {
}
if len(invalidTopics) > 0 {
ctx.JSON(422, map[string]interface{}{
ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{
"invalidTopics": invalidTopics,
"message": ctx.Tr("repo.topic.format_prompt"),
})
@@ -48,13 +49,13 @@ func TopicsPost(ctx *context.Context) {
err := models.SaveTopics(ctx.Repo.Repository.ID, validTopics...)
if err != nil {
log.Error("SaveTopics failed: %v", err)
ctx.JSON(500, map[string]interface{}{
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
"message": "Save topics failed.",
})
return
}
ctx.JSON(200, map[string]interface{}{
ctx.JSON(http.StatusOK, map[string]interface{}{
"status": "ok",
})
}