Do not show 500 error when default branch doesn't exist (#34096) (#34097)

Backport #34096
This commit is contained in:
wxiaoguang
2025-04-02 18:16:41 +08:00
committed by GitHub
parent 25e409e025
commit 8f75f61b64
6 changed files with 49 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ package actions
import (
"bytes"
stdCtx "context"
"errors"
"fmt"
"net/http"
"slices"
@@ -77,7 +78,11 @@ func List(ctx *context.Context) {
return
} else if !empty {
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
if err != nil {
if errors.Is(err, util.ErrNotExist) {
ctx.Data["NotFoundPrompt"] = ctx.Tr("repo.branch.default_branch_not_exist", ctx.Repo.Repository.DefaultBranch)
ctx.NotFound("GetBranchCommit", err)
return
} else if err != nil {
ctx.ServerError("GetBranchCommit", err)
return
}