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

@@ -29,7 +29,7 @@ func Home(ctx *context.Context) {
uname := ctx.PathParam("username")
if strings.HasSuffix(uname, ".keys") || strings.HasSuffix(uname, ".gpg") {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}

View File

@@ -41,7 +41,7 @@ func Members(ctx *context.Context) {
if ctx.Doer != nil {
isMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOrgMember")
ctx.HTTPError(http.StatusInternalServerError, "IsOrgMember")
return
}
opts.IsDoerMember = isMember
@@ -50,7 +50,7 @@ func Members(ctx *context.Context) {
total, err := organization.CountOrgMembers(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CountOrgMembers")
ctx.HTTPError(http.StatusInternalServerError, "CountOrgMembers")
return
}
@@ -93,19 +93,19 @@ func MembersAction(ctx *context.Context) {
switch ctx.PathParam("action") {
case "private":
if ctx.Doer.ID != member.ID && !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
err = organization.ChangeOrgUserStatus(ctx, org.ID, member.ID, false)
case "public":
if ctx.Doer.ID != member.ID && !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
err = organization.ChangeOrgUserStatus(ctx, org.ID, member.ID, true)
case "remove":
if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
err = org_service.RemoveOrgUser(ctx, org, member)

View File

@@ -64,7 +64,7 @@ func UpdateLabel(ctx *context.Context) {
if err != nil {
switch {
case issues_model.IsErrOrgLabelNotExist(err):
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
default:
ctx.ServerError("UpdateLabel", err)
}

View File

@@ -36,7 +36,7 @@ const (
// MustEnableProjects check if projects are enabled in settings
func MustEnableProjects(ctx *context.Context) {
if unit.TypeProjects.UnitGlobalDisabled() {
ctx.NotFound("EnableProjects", nil)
ctx.NotFound(nil)
return
}
}
@@ -227,7 +227,7 @@ func DeleteProject(ctx *context.Context) {
return
}
if p.OwnerID != ctx.ContextUser.ID {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -256,7 +256,7 @@ func RenderEditProject(ctx *context.Context) {
return
}
if p.OwnerID != ctx.ContextUser.ID {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -301,7 +301,7 @@ func EditProjectPost(ctx *context.Context) {
return
}
if p.OwnerID != ctx.ContextUser.ID {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -329,7 +329,7 @@ func ViewProject(ctx *context.Context) {
return
}
if project.OwnerID != ctx.ContextUser.ID {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
if err := project.LoadOwner(ctx); err != nil {
@@ -609,7 +609,7 @@ func MoveIssues(ctx *context.Context) {
return
}
if project.OwnerID != ctx.ContextUser.ID {
ctx.NotFound("InvalidRepoID", nil)
ctx.NotFound(nil)
return
}
@@ -620,7 +620,7 @@ func MoveIssues(ctx *context.Context) {
}
if column.ProjectID != project.ID {
ctx.NotFound("ColumnNotInProject", nil)
ctx.NotFound(nil)
return
}

View File

@@ -74,7 +74,7 @@ func TeamsAction(ctx *context.Context) {
switch ctx.PathParam("action") {
case "join":
if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
err = org_service.AddTeamMember(ctx, ctx.Org.Team, ctx.Doer)
@@ -96,7 +96,7 @@ func TeamsAction(ctx *context.Context) {
return
case "remove":
if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
@@ -123,7 +123,7 @@ func TeamsAction(ctx *context.Context) {
return
case "add":
if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
uname := strings.ToLower(ctx.FormString("uname"))
@@ -167,7 +167,7 @@ func TeamsAction(ctx *context.Context) {
page = "team"
case "remove_invite":
if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
@@ -228,7 +228,7 @@ func checkIsOrgMemberAndRedirect(ctx *context.Context, defaultRedirect string) {
// TeamsRepoAction operate team's repository
func TeamsRepoAction(ctx *context.Context) {
if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
@@ -568,7 +568,7 @@ func TeamInvite(ctx *context.Context) {
invite, org, team, inviter, err := getTeamInviteFromContext(ctx)
if err != nil {
if org_model.IsErrTeamInviteNotFound(err) {
ctx.NotFound("ErrTeamInviteNotFound", err)
ctx.NotFound(err)
} else {
ctx.ServerError("getTeamInviteFromContext", err)
}
@@ -589,7 +589,7 @@ func TeamInvitePost(ctx *context.Context) {
invite, org, team, _, err := getTeamInviteFromContext(ctx)
if err != nil {
if org_model.IsErrTeamInviteNotFound(err) {
ctx.NotFound("ErrTeamInviteNotFound", err)
ctx.NotFound(err)
} else {
ctx.ServerError("getTeamInviteFromContext", err)
}