Refactor error system (#33626)

This commit is contained in:
wxiaoguang 2025-02-18 04:41:03 +08:00 committed by GitHub
parent 7df09e31fa
commit 15e020eec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
75 changed files with 703 additions and 693 deletions

View file

@ -26,12 +26,12 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
OrderBy: "id ASC",
})
if err != nil {
ctx.APIError(http.StatusInternalServerError, err)
ctx.APIErrorInternal(err)
return
}
if err := repos.LoadAttributes(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err)
ctx.APIErrorInternal(err)
return
}
@ -39,7 +39,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
for i := range repos {
permission, err := access_model.GetUserRepoPermission(ctx, repos[i], ctx.Doer)
if err != nil {
ctx.APIError(http.StatusInternalServerError, err)
ctx.APIErrorInternal(err)
return
}
if ctx.IsSigned && ctx.Doer.IsAdmin || permission.HasAnyUnitAccess() {
@ -113,19 +113,19 @@ func ListMyRepos(ctx *context.APIContext) {
repos, count, err := repo_model.SearchRepository(ctx, opts)
if err != nil {
ctx.APIError(http.StatusInternalServerError, err)
ctx.APIErrorInternal(err)
return
}
results := make([]*api.Repository, len(repos))
for i, repo := range repos {
if err = repo.LoadOwner(ctx); err != nil {
ctx.APIError(http.StatusInternalServerError, err)
ctx.APIErrorInternal(err)
return
}
permission, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer)
if err != nil {
ctx.APIError(http.StatusInternalServerError, err)
ctx.APIErrorInternal(err)
}
results[i] = convert.ToRepo(ctx, repo, permission)
}