summaryrefslogtreecommitdiffstats
path: root/routers/repo/repo.go
diff options
context:
space:
mode:
authorMorgan Bazalgette <git@howl.moe>2018-01-10 22:34:17 +0100
committerLauris BH <lauris@nix.lv>2018-01-10 23:34:17 +0200
commit65861900cda3bb6d9e2aa80b808b0000383c04b3 (patch)
tree8569d93b6ef092b30b35a4d4da906c6b6950e2ee /routers/repo/repo.go
parent45c264f681e3f7e1a22a191029836a690959aac3 (diff)
downloadgitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.tar.gz
gitea-65861900cda3bb6d9e2aa80b808b0000383c04b3.zip
Handle refactor (#3339)
* Replace all ctx.Handle with ctx.ServerError or ctx.NotFound * Change Handle(403) to NotFound, avoid using macaron's NotFound
Diffstat (limited to 'routers/repo/repo.go')
-rw-r--r--routers/repo/repo.go32
1 files changed, 16 insertions, 16 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 4cd7c8062c..20ea1e24a2 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -31,14 +31,14 @@ const (
// MustBeNotBare render when a repo is a bare git dir
func MustBeNotBare(ctx *context.Context) {
if ctx.Repo.Repository.IsBare {
- ctx.Handle(404, "MustBeNotBare", nil)
+ ctx.NotFound("MustBeNotBare", nil)
}
}
// MustBeEditable check that repo can be edited
func MustBeEditable(ctx *context.Context) {
if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
- ctx.Handle(404, "", nil)
+ ctx.NotFound("", nil)
return
}
}
@@ -46,14 +46,14 @@ func MustBeEditable(ctx *context.Context) {
// MustBeAbleToUpload check that repo can be uploaded to
func MustBeAbleToUpload(ctx *context.Context) {
if !setting.Repository.Upload.Enabled {
- ctx.Handle(404, "", nil)
+ ctx.NotFound("", nil)
}
}
func checkContextUser(ctx *context.Context, uid int64) *models.User {
orgs, err := models.GetOwnedOrgsByUserIDDesc(ctx.User.ID, "updated_unix")
if err != nil {
- ctx.Handle(500, "GetOwnedOrgsByUserIDDesc", err)
+ ctx.ServerError("GetOwnedOrgsByUserIDDesc", err)
return nil
}
ctx.Data["Orgs"] = orgs
@@ -69,7 +69,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
}
if err != nil {
- ctx.Handle(500, "GetUserByID", fmt.Errorf("[%d]: %v", uid, err))
+ ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %v", uid, err))
return nil
}
@@ -81,7 +81,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
if !ctx.User.IsAdmin {
isOwner, err := org.IsOwnedBy(ctx.User.ID)
if err != nil {
- ctx.Handle(500, "IsOwnedBy", err)
+ ctx.ServerError("IsOwnedBy", err)
return nil
} else if !isOwner {
ctx.Error(403)
@@ -143,7 +143,7 @@ func handleCreateError(ctx *context.Context, owner *models.User, err error, name
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
default:
- ctx.Handle(500, name, err)
+ ctx.ServerError(name, err)
}
}
@@ -235,10 +235,10 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
case addrErr.IsInvalidPath:
ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), tplMigrate, &form)
default:
- ctx.Handle(500, "Unknown error", err)
+ ctx.ServerError("Unknown error", err)
}
} else {
- ctx.Handle(500, "ParseRemoteAddr", err)
+ ctx.ServerError("ParseRemoteAddr", err)
}
return
}
@@ -303,7 +303,7 @@ func Action(ctx *context.Context) {
}
if err != nil {
- ctx.Handle(500, fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
+ ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
return
}
@@ -342,7 +342,7 @@ func Download(ctx *context.Context) {
if !com.IsDir(archivePath) {
if err := os.MkdirAll(archivePath, os.ModePerm); err != nil {
- ctx.Handle(500, "Download -> os.MkdirAll(archivePath)", err)
+ ctx.ServerError("Download -> os.MkdirAll(archivePath)", err)
return
}
}
@@ -356,30 +356,30 @@ func Download(ctx *context.Context) {
if gitRepo.IsBranchExist(refName) {
commit, err = gitRepo.GetBranchCommit(refName)
if err != nil {
- ctx.Handle(500, "GetBranchCommit", err)
+ ctx.ServerError("GetBranchCommit", err)
return
}
} else if gitRepo.IsTagExist(refName) {
commit, err = gitRepo.GetTagCommit(refName)
if err != nil {
- ctx.Handle(500, "GetTagCommit", err)
+ ctx.ServerError("GetTagCommit", err)
return
}
} else if len(refName) >= 4 && len(refName) <= 40 {
commit, err = gitRepo.GetCommit(refName)
if err != nil {
- ctx.Handle(404, "GetCommit", nil)
+ ctx.NotFound("GetCommit", nil)
return
}
} else {
- ctx.Handle(404, "Download", nil)
+ ctx.NotFound("Download", nil)
return
}
archivePath = path.Join(archivePath, base.ShortSha(commit.ID.String())+ext)
if !com.IsFile(archivePath) {
if err := commit.CreateArchive(archivePath, archiveType); err != nil {
- ctx.Handle(500, "Download -> CreateArchive "+archivePath, err)
+ ctx.ServerError("Download -> CreateArchive "+archivePath, err)
return
}
}