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

@@ -189,13 +189,13 @@ func SettingsPost(ctx *context.Context) {
case "mirror":
if !setting.Mirror.Enabled || !repo.IsMirror || repo.IsArchived {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
pullMirror, err := repo_model.GetMirrorByRepoID(ctx, ctx.Repo.Repository.ID)
if err == repo_model.ErrMirrorNotExist {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
if err != nil {
@@ -283,7 +283,7 @@ func SettingsPost(ctx *context.Context) {
case "mirror-sync":
if !setting.Mirror.Enabled || !repo.IsMirror || repo.IsArchived {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -294,13 +294,13 @@ func SettingsPost(ctx *context.Context) {
case "push-mirror-sync":
if !setting.Mirror.Enabled {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
m, _, _ := repo_model.GetPushMirrorByIDAndRepoID(ctx, form.PushMirrorID, repo.ID)
if m == nil {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -311,7 +311,7 @@ func SettingsPost(ctx *context.Context) {
case "push-mirror-update":
if !setting.Mirror.Enabled || repo.IsArchived {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -327,7 +327,7 @@ func SettingsPost(ctx *context.Context) {
m, _, _ := repo_model.GetPushMirrorByIDAndRepoID(ctx, form.PushMirrorID, repo.ID)
if m == nil {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -349,7 +349,7 @@ func SettingsPost(ctx *context.Context) {
case "push-mirror-remove":
if !setting.Mirror.Enabled || repo.IsArchived {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -359,7 +359,7 @@ func SettingsPost(ctx *context.Context) {
m, _, _ := repo_model.GetPushMirrorByIDAndRepoID(ctx, form.PushMirrorID, repo.ID)
if m == nil {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -378,7 +378,7 @@ func SettingsPost(ctx *context.Context) {
case "push-mirror-add":
if setting.Mirror.DisableNewPush || repo.IsArchived {
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -650,7 +650,7 @@ func SettingsPost(ctx *context.Context) {
case "admin":
if !ctx.Doer.IsAdmin {
ctx.Error(http.StatusForbidden)
ctx.HTTPError(http.StatusForbidden)
return
}
@@ -670,7 +670,7 @@ func SettingsPost(ctx *context.Context) {
case "admin_index":
if !ctx.Doer.IsAdmin {
ctx.Error(http.StatusForbidden)
ctx.HTTPError(http.StatusForbidden)
return
}
@@ -682,12 +682,12 @@ func SettingsPost(ctx *context.Context) {
}
case "code":
if !setting.Indexer.RepoIndexerEnabled {
ctx.Error(http.StatusForbidden)
ctx.HTTPError(http.StatusForbidden)
return
}
code.UpdateRepoIndexer(ctx.Repo.Repository)
default:
ctx.NotFound("", nil)
ctx.NotFound(nil)
return
}
@@ -698,7 +698,7 @@ func SettingsPost(ctx *context.Context) {
case "convert":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@@ -707,7 +707,7 @@ func SettingsPost(ctx *context.Context) {
}
if !repo.IsMirror {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
repo.IsMirror = false
@@ -725,7 +725,7 @@ func SettingsPost(ctx *context.Context) {
case "convert_fork":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
if err := repo.LoadOwner(ctx); err != nil {
@@ -738,7 +738,7 @@ func SettingsPost(ctx *context.Context) {
}
if !repo.IsFork {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
@@ -762,7 +762,7 @@ func SettingsPost(ctx *context.Context) {
case "transfer":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@@ -820,7 +820,7 @@ func SettingsPost(ctx *context.Context) {
case "cancel_transfer":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
@@ -846,7 +846,7 @@ func SettingsPost(ctx *context.Context) {
case "delete":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@@ -870,7 +870,7 @@ func SettingsPost(ctx *context.Context) {
case "delete-wiki":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusNotFound)
ctx.HTTPError(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@@ -889,7 +889,7 @@ func SettingsPost(ctx *context.Context) {
case "archive":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusForbidden)
ctx.HTTPError(http.StatusForbidden)
return
}
@@ -920,7 +920,7 @@ func SettingsPost(ctx *context.Context) {
case "unarchive":
if !ctx.Repo.IsOwner() {
ctx.Error(http.StatusForbidden)
ctx.HTTPError(http.StatusForbidden)
return
}
@@ -979,7 +979,7 @@ func SettingsPost(ctx *context.Context) {
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
default:
ctx.NotFound("", nil)
ctx.NotFound(nil)
}
}