Display friendly error message (#29105) (#29363)

Backport #29105 

`ctx.Error` only displays the text but `ctx.ServerError` renders the
usual error page.

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
This commit is contained in:
Lunny Xiao 2024-02-24 19:01:18 +08:00 committed by GitHub
parent 6624f257d3
commit a1c0b3a02e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -61,17 +61,17 @@ func List(ctx *context.Context) {
var workflows []Workflow var workflows []Workflow
if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil { if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.ServerError("IsEmpty", err)
return return
} else if !empty { } else if !empty {
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.ServerError("GetBranchCommit", err)
return return
} }
entries, err := actions.ListWorkflows(commit) entries, err := actions.ListWorkflows(commit)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.ServerError("ListWorkflows", err)
return return
} }
@ -96,7 +96,7 @@ func List(ctx *context.Context) {
workflow := Workflow{Entry: *entry} workflow := Workflow{Entry: *entry}
content, err := actions.GetContentFromEntry(entry) content, err := actions.GetContentFromEntry(entry)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.ServerError("GetContentFromEntry", err)
return return
} }
wf, err := model.ReadWorkflow(bytes.NewReader(content)) wf, err := model.ReadWorkflow(bytes.NewReader(content))
@ -173,7 +173,7 @@ func List(ctx *context.Context) {
runs, total, err := actions_model.FindRuns(ctx, opts) runs, total, err := actions_model.FindRuns(ctx, opts)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.ServerError("FindAndCount", err)
return return
} }
@ -182,7 +182,7 @@ func List(ctx *context.Context) {
} }
if err := runs.LoadTriggerUser(ctx); err != nil { if err := runs.LoadTriggerUser(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.ServerError("LoadTriggerUser", err)
return return
} }
@ -190,7 +190,7 @@ func List(ctx *context.Context) {
actors, err := actions_model.GetActors(ctx, ctx.Repo.Repository.ID) actors, err := actions_model.GetActors(ctx, ctx.Repo.Repository.ID)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.ServerError("GetActors", err)
return return
} }
ctx.Data["Actors"] = repo.MakeSelfOnTop(ctx.Doer, actors) ctx.Data["Actors"] = repo.MakeSelfOnTop(ctx.Doer, actors)