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

@@ -49,6 +49,6 @@ func SetDefaultBranchPost(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
default:
ctx.NotFound("", nil)
ctx.NotFound(nil)
}
}

View File

@@ -34,7 +34,7 @@ func GitHooksEdit(ctx *context.Context) {
hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil {
if err == git.ErrNotValidHook {
ctx.NotFound("GetHook", err)
ctx.NotFound(err)
} else {
ctx.ServerError("GetHook", err)
}
@@ -50,7 +50,7 @@ func GitHooksEditPost(ctx *context.Context) {
hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil {
if err == git.ErrNotValidHook {
ctx.NotFound("GetHook", err)
ctx.NotFound(err)
} else {
ctx.ServerError("GetHook", err)
}

View File

@@ -41,7 +41,7 @@ const (
// LFSFiles shows a repository's LFS files
func LFSFiles(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSFiles", nil)
ctx.NotFound(nil)
return
}
page := ctx.FormInt("page")
@@ -71,7 +71,7 @@ func LFSFiles(ctx *context.Context) {
// LFSLocks shows a repository's LFS locks
func LFSLocks(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSLocks", nil)
ctx.NotFound(nil)
return
}
ctx.Data["LFSFilesLink"] = ctx.Repo.RepoLink + "/settings/lfs"
@@ -197,7 +197,7 @@ func LFSLocks(ctx *context.Context) {
// LFSLockFile locks a file
func LFSLockFile(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSLocks", nil)
ctx.NotFound(nil)
return
}
originalPath := ctx.FormString("path")
@@ -238,7 +238,7 @@ func LFSLockFile(ctx *context.Context) {
// LFSUnlock forcibly unlocks an LFS lock
func LFSUnlock(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSUnlock", nil)
ctx.NotFound(nil)
return
}
_, err := git_model.DeleteLFSLockByID(ctx, ctx.PathParamInt64("lid"), ctx.Repo.Repository, ctx.Doer, true)
@@ -252,7 +252,7 @@ func LFSUnlock(ctx *context.Context) {
// LFSFileGet serves a single LFS file
func LFSFileGet(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSFileGet", nil)
ctx.NotFound(nil)
return
}
ctx.Data["LFSFilesLink"] = ctx.Repo.RepoLink + "/settings/lfs"
@@ -260,7 +260,7 @@ func LFSFileGet(ctx *context.Context) {
p := lfs.Pointer{Oid: oid}
if !p.IsValid() {
ctx.NotFound("LFSFileGet", nil)
ctx.NotFound(nil)
return
}
@@ -269,7 +269,7 @@ func LFSFileGet(ctx *context.Context) {
meta, err := git_model.GetLFSMetaObjectByOid(ctx, ctx.Repo.Repository.ID, oid)
if err != nil {
if err == git_model.ErrLFSObjectNotExist {
ctx.NotFound("LFSFileGet", nil)
ctx.NotFound(nil)
return
}
ctx.ServerError("LFSFileGet", err)
@@ -350,13 +350,13 @@ func LFSFileGet(ctx *context.Context) {
// LFSDelete disassociates the provided oid from the repository and if the lfs file is no longer associated with any repositories - deletes it
func LFSDelete(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSDelete", nil)
ctx.NotFound(nil)
return
}
oid := ctx.PathParam("oid")
p := lfs.Pointer{Oid: oid}
if !p.IsValid() {
ctx.NotFound("LFSDelete", nil)
ctx.NotFound(nil)
return
}
@@ -381,13 +381,13 @@ func LFSDelete(ctx *context.Context) {
// LFSFileFind guesses a sha for the provided oid (or uses the provided sha) and then finds the commits that contain this sha
func LFSFileFind(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSFind", nil)
ctx.NotFound(nil)
return
}
oid := ctx.FormString("oid")
size := ctx.FormInt64("size")
if len(oid) == 0 || size == 0 {
ctx.NotFound("LFSFind", nil)
ctx.NotFound(nil)
return
}
sha := ctx.FormString("sha")
@@ -421,7 +421,7 @@ func LFSFileFind(ctx *context.Context) {
// LFSPointerFiles will search the repository for pointer files and report which are missing LFS files in the content store
func LFSPointerFiles(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSFileGet", nil)
ctx.NotFound(nil)
return
}
ctx.Data["PageIsSettingsLFS"] = true
@@ -532,7 +532,7 @@ func LFSPointerFiles(ctx *context.Context) {
// LFSAutoAssociate auto associates accessible lfs files
func LFSAutoAssociate(ctx *context.Context) {
if !setting.LFS.StartServer {
ctx.NotFound("LFSAutoAssociate", nil)
ctx.NotFound(nil)
return
}
oids := ctx.FormStrings("oid")

View File

@@ -340,7 +340,7 @@ func RenameBranchPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RenameBranchForm)
if !ctx.Repo.CanCreateBranch() {
ctx.NotFound("RenameBranch", nil)
ctx.NotFound(nil)
return
}

View File

@@ -183,7 +183,7 @@ func selectProtectedTagByContext(ctx *context.Context) *git_model.ProtectedTag {
return tag
}
ctx.NotFound("", fmt.Errorf("ProtectedTag[%v] not associated to repository %v", id, ctx.Repo.Repository))
ctx.NotFound(fmt.Errorf("ProtectedTag[%v] not associated to repository %v", id, ctx.Repo.Repository))
return nil
}

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)
}
}

View File

@@ -112,7 +112,7 @@ func getOwnerRepoCtx(ctx *context.Context) (*ownerRepoCtx, error) {
func checkHookType(ctx *context.Context) string {
hookType := strings.ToLower(ctx.PathParam("type"))
if !util.SliceContainsString(setting.Webhook.Types, hookType, true) {
ctx.NotFound("checkHookType", nil)
ctx.NotFound(nil)
return ""
}
return hookType
@@ -601,7 +601,7 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
}
if err != nil || w == nil {
if webhook.IsErrWebhookNotExist(err) {
ctx.NotFound("GetWebhookByID", nil)
ctx.NotFound(nil)
} else {
ctx.ServerError("GetWebhookByID", err)
}
@@ -718,7 +718,7 @@ func ReplayWebhook(ctx *context.Context) {
if err := webhook_service.ReplayHookTask(ctx, w, hookTaskUUID); err != nil {
if webhook.IsErrHookTaskNotExist(err) {
ctx.NotFound("ReplayHookTask", nil)
ctx.NotFound(nil)
} else {
ctx.ServerError("ReplayHookTask", err)
}