Skip to content

Commit

Permalink
Mark TemplateLoading error as "UnprocessableEntity" (go-gitea#19445)
Browse files Browse the repository at this point in the history
- Backport go-gitea#19445
  - Don't return Internal Server error if the user provide incorrect label template, instead return UnprocessableEntity.
  - Resolves go-gitea#19399
  • Loading branch information
Gusted committed Apr 20, 2022
1 parent 6bddfd3 commit 95f8671
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
Expand Down Expand Up @@ -160,7 +161,7 @@ func Search(ctx *context.APIContext) {
opts.Collaborate = util.OptionalBoolFalse
}

var mode = ctx.FormString("mode")
mode := ctx.FormString("mode")
switch mode {
case "source":
opts.Fork = util.OptionalBoolFalse
Expand All @@ -186,9 +187,9 @@ func Search(ctx *context.APIContext) {
opts.IsPrivate = util.OptionalBoolOf(ctx.FormBool("is_private"))
}

var sortMode = ctx.FormString("sort")
sortMode := ctx.FormString("sort")
if len(sortMode) > 0 {
var sortOrder = ctx.FormString("order")
sortOrder := ctx.FormString("order")
if len(sortOrder) == 0 {
sortOrder = "asc"
}
Expand Down Expand Up @@ -264,7 +265,8 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
if repo_model.IsErrRepoAlreadyExist(err) {
ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.")
} else if db.IsErrNameReserved(err) ||
db.IsErrNamePatternNotAllowed(err) {
db.IsErrNamePatternNotAllowed(err) ||
repo_module.IsErrIssueLabelTemplateLoad(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateRepository", err)
Expand Down

0 comments on commit 95f8671

Please sign in to comment.