1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +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

@@ -28,13 +28,13 @@ func listMembers(ctx *context.APIContext, isMember bool) {
count, err := organization.CountOrgMembers(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
members, _, err := organization.FindOrgMembers(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
ctx.APIErrorInternal(err)
return
}
@@ -82,7 +82,7 @@ func ListMembers(ctx *context.APIContext) {
if ctx.Doer != nil {
isMember, err = ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
}
@@ -150,20 +150,20 @@ func IsMember(ctx *context.APIContext) {
if ctx.Doer != nil {
userIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
ctx.APIError(http.StatusInternalServerError, err)
return
} else if userIsMember || ctx.Doer.IsAdmin {
userToCheckIsMember, err := ctx.Org.Organization.IsOrgMember(ctx, userToCheck.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
ctx.APIError(http.StatusInternalServerError, err)
} else if userToCheckIsMember {
ctx.Status(http.StatusNoContent)
} else {
ctx.NotFound()
ctx.APIErrorNotFound()
}
return
} else if ctx.Doer.ID == userToCheck.ID {
ctx.NotFound()
ctx.APIErrorNotFound()
return
}
}
@@ -200,13 +200,13 @@ func IsPublicMember(ctx *context.APIContext) {
}
is, err := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, userToCheck.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsPublicMembership", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
if is {
ctx.Status(http.StatusNoContent)
} else {
ctx.NotFound()
ctx.APIErrorNotFound()
}
}
@@ -241,12 +241,12 @@ func PublicizeMember(ctx *context.APIContext) {
return
}
if userToPublicize.ID != ctx.Doer.ID {
ctx.Error(http.StatusForbidden, "", "Cannot publicize another member")
ctx.APIError(http.StatusForbidden, "Cannot publicize another member")
return
}
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToPublicize.ID, true)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
ctx.Status(http.StatusNoContent)
@@ -283,12 +283,12 @@ func ConcealMember(ctx *context.APIContext) {
return
}
if userToConceal.ID != ctx.Doer.ID {
ctx.Error(http.StatusForbidden, "", "Cannot conceal another member")
ctx.APIError(http.StatusForbidden, "Cannot conceal another member")
return
}
err := organization.ChangeOrgUserStatus(ctx, ctx.Org.Organization.ID, userToConceal.ID, false)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ChangeOrgUserStatus", err)
ctx.APIError(http.StatusInternalServerError, err)
return
}
ctx.Status(http.StatusNoContent)
@@ -323,7 +323,7 @@ func DeleteMember(ctx *context.APIContext) {
return
}
if err := org_service.RemoveOrgUser(ctx, ctx.Org.Organization, member); err != nil {
ctx.Error(http.StatusInternalServerError, "RemoveOrgUser", err)
ctx.APIError(http.StatusInternalServerError, err)
}
ctx.Status(http.StatusNoContent)
}