Refactor error system (#33610)

This commit is contained in:
wxiaoguang 2025-02-17 14:13:17 +08:00 committed by GitHub
parent 69de5a65c2
commit f35850f48e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
184 changed files with 2100 additions and 2106 deletions

View file

@ -59,7 +59,7 @@ func RefCommits(ctx *context.Context) {
func Commits(ctx *context.Context) {
ctx.Data["PageIsCommits"] = true
if ctx.Repo.Commit == nil {
ctx.NotFound("Commit not found", nil)
ctx.NotFound(nil)
return
}
ctx.Data["PageIsViewCode"] = true
@ -226,7 +226,7 @@ func FileHistory(ctx *context.Context) {
ctx.ServerError("FileCommitsCount", err)
return
} else if commitsCount == 0 {
ctx.NotFound("FileCommitsCount", nil)
ctx.NotFound(nil)
return
}
@ -297,7 +297,7 @@ func Diff(ctx *context.Context) {
commit, err := gitRepo.GetCommit(commitID)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound("Repo.GitRepo.GetCommit", err)
ctx.NotFound(err)
} else {
ctx.ServerError("Repo.GitRepo.GetCommit", err)
}
@ -324,7 +324,7 @@ func Diff(ctx *context.Context) {
FileOnly: fileOnly,
}, files...)
if err != nil {
ctx.NotFound("GetDiff", err)
ctx.NotFound(err)
return
}
@ -332,7 +332,7 @@ func Diff(ctx *context.Context) {
for i := 0; i < commit.ParentCount(); i++ {
sha, err := commit.ParentID(i)
if err != nil {
ctx.NotFound("repo.Diff", err)
ctx.NotFound(err)
return
}
parents[i] = sha.String()
@ -347,7 +347,7 @@ func Diff(ctx *context.Context) {
if commit.ParentCount() > 0 {
parentCommit, err = gitRepo.GetCommit(parents[0])
if err != nil {
ctx.NotFound("GetParentCommit", err)
ctx.NotFound(err)
return
}
}
@ -421,8 +421,7 @@ func RawDiff(ctx *context.Context) {
ctx.Resp,
); err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound("GetRawDiff",
errors.New("commit "+ctx.PathParam("sha")+" does not exist."))
ctx.NotFound(errors.New("commit " + ctx.PathParam("sha") + " does not exist."))
return
}
ctx.ServerError("GetRawDiff", err)