1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 10:18:38 +00:00

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
184 changed files with 2100 additions and 2106 deletions

View File

@@ -258,7 +258,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
ci.HeadUser, err = user_model.GetUserByName(ctx, headInfos[0])
if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName", nil)
ctx.NotFound(nil)
} else {
ctx.ServerError("GetUserByName", err)
}
@@ -273,7 +273,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
ci.HeadRepo, err = repo_model.GetRepositoryByOwnerAndName(ctx, headInfosSplit[0], headInfosSplit[1])
if err != nil {
if repo_model.IsErrRepoNotExist(err) {
ctx.NotFound("GetRepositoryByOwnerAndName", nil)
ctx.NotFound(nil)
} else {
ctx.ServerError("GetRepositoryByOwnerAndName", err)
}
@@ -281,7 +281,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
}
if err := ci.HeadRepo.LoadOwner(ctx); err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByName", nil)
ctx.NotFound(nil)
} else {
ctx.ServerError("GetUserByName", err)
}
@@ -292,7 +292,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
isSameRepo = ci.HeadRepo.ID == ctx.Repo.Repository.ID
}
} else {
ctx.NotFound("CompareAndPullRequest", nil)
ctx.NotFound(nil)
return nil
}
ctx.Data["HeadUser"] = ci.HeadUser
@@ -318,7 +318,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
}
return nil
} else {
ctx.NotFound("IsRefExist", nil)
ctx.NotFound(nil)
return nil
}
}
@@ -408,7 +408,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
}
defer ci.HeadGitRepo.Close()
} else {
ctx.NotFound("ParseCompareInfo", nil)
ctx.NotFound(nil)
return nil
}
@@ -430,7 +430,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
baseRepo,
permBase)
}
ctx.NotFound("ParseCompareInfo", nil)
ctx.NotFound(nil)
return nil
}
@@ -449,7 +449,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
ci.HeadRepo,
permHead)
}
ctx.NotFound("ParseCompareInfo", nil)
ctx.NotFound(nil)
return nil
}
ctx.Data["CanWriteToHeadRepo"] = permHead.CanWrite(unit.TypeCode)
@@ -513,7 +513,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
ctx.Data["HeadBranch"] = ci.HeadBranch
headIsCommit = true
} else {
ctx.NotFound("IsRefExist", nil)
ctx.NotFound(nil)
return nil
}
}
@@ -533,7 +533,7 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
baseRepo,
permBase)
}
ctx.NotFound("ParseCompareInfo", nil)
ctx.NotFound(nil)
return nil
}
@@ -880,7 +880,7 @@ func ExcerptBlob(ctx *context.Context) {
chunkSize := gitdiff.BlobExcerptChunkSize
commit, err := gitRepo.GetCommit(commitID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetCommit")
ctx.HTTPError(http.StatusInternalServerError, "GetCommit")
return
}
section := &gitdiff.DiffSection{
@@ -909,7 +909,7 @@ func ExcerptBlob(ctx *context.Context) {
idxRight = lastRight
}
if err != nil {
ctx.Error(http.StatusInternalServerError, "getExcerptLines")
ctx.HTTPError(http.StatusInternalServerError, "getExcerptLines")
return
}
if idxRight > lastRight {