use ctx.Handle to handle 404 page

release/v1.15
FuXiaoHei 2014-03-23 13:12:55 +08:00
parent ad31893bbb
commit 47493a0191
5 changed files with 34 additions and 20 deletions

View File

@ -36,7 +36,7 @@ func Issues(ctx *middleware.Context, params martini.Params) {
func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
if !ctx.Repo.IsOwner { if !ctx.Repo.IsOwner {
ctx.Error(404) ctx.Handle(404, "issue.CreateIssue", nil)
return return
} }
@ -65,14 +65,14 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
func ViewIssue(ctx *middleware.Context, params martini.Params) { func ViewIssue(ctx *middleware.Context, params martini.Params) {
issueid, err := base.StrTo(params["issueid"]).Int() issueid, err := base.StrTo(params["issueid"]).Int()
if err != nil { if err != nil {
ctx.Error(404) ctx.Handle(404, "issue.ViewIssue", err)
return return
} }
issue, err := models.GetIssueById(int64(issueid)) issue, err := models.GetIssueById(int64(issueid))
if err != nil { if err != nil {
if err == models.ErrIssueNotExist { if err == models.ErrIssueNotExist {
ctx.Error(404) ctx.Handle(404, "issue.ViewIssue", err)
} else { } else {
ctx.Handle(200, "issue.ViewIssue", err) ctx.Handle(200, "issue.ViewIssue", err)
} }

View File

@ -86,7 +86,7 @@ func Branches(ctx *middleware.Context, params martini.Params) {
ctx.Handle(200, "repo.Branches", err) ctx.Handle(200, "repo.Branches", err)
return return
} else if len(brs) == 0 { } else if len(brs) == 0 {
ctx.Error(404) ctx.Handle(404, "repo.Branches", nil)
return return
} }
@ -123,8 +123,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
// Branches. // Branches.
brs, err := models.GetBranches(params["username"], params["reponame"]) brs, err := models.GetBranches(params["username"], params["reponame"])
if err != nil { if err != nil {
log.Error("repo.Single(GetBranches): %v", err) //log.Error("repo.Single(GetBranches): %v", err)
ctx.Error(404) ctx.Handle(404, "repo.Single(GetBranches)", err)
return return
} else if ctx.Repo.Repository.IsBare { } else if ctx.Repo.Repository.IsBare {
ctx.Data["IsBareRepo"] = true ctx.Data["IsBareRepo"] = true
@ -138,15 +138,15 @@ func Single(ctx *middleware.Context, params martini.Params) {
params["branchname"], params["commitid"], treename) params["branchname"], params["commitid"], treename)
if err != nil && err != models.ErrRepoFileNotExist { if err != nil && err != models.ErrRepoFileNotExist {
log.Error("repo.Single(GetTargetFile): %v", err) //log.Error("repo.Single(GetTargetFile): %v", err)
ctx.Error(404) ctx.Handle(404, "repo.Single(GetTargetFile)", err)
return return
} }
branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"] branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"]
if len(treename) != 0 && repoFile == nil { if len(treename) != 0 && repoFile == nil {
ctx.Error(404) ctx.Handle(404, "repo.Single", nil)
return return
} }
@ -154,8 +154,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
if repoFile.Size > 1024*1024 || repoFile.Filemode != git.FileModeBlob { if repoFile.Size > 1024*1024 || repoFile.Filemode != git.FileModeBlob {
ctx.Data["FileIsLarge"] = true ctx.Data["FileIsLarge"] = true
} else if blob, err := repoFile.LookupBlob(); err != nil { } else if blob, err := repoFile.LookupBlob(); err != nil {
log.Error("repo.Single(repoFile.LookupBlob): %v", err) //log.Error("repo.Single(repoFile.LookupBlob): %v", err)
ctx.Error(404) ctx.Handle(404, "repo.Single(repoFile.LookupBlob)", err)
} else { } else {
ctx.Data["IsFile"] = true ctx.Data["IsFile"] = true
ctx.Data["FileName"] = repoFile.Name ctx.Data["FileName"] = repoFile.Name
@ -179,8 +179,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
files, err := models.GetReposFiles(params["username"], params["reponame"], files, err := models.GetReposFiles(params["username"], params["reponame"],
params["branchname"], params["commitid"], treename) params["branchname"], params["commitid"], treename)
if err != nil { if err != nil {
log.Error("repo.Single(GetReposFiles): %v", err) //log.Error("repo.Single(GetReposFiles): %v", err)
ctx.Error(404) ctx.Handle(404, "repo.Single(GetReposFiles)", err)
return return
} }
@ -203,8 +203,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
if readmeFile.Size > 1024*1024 || readmeFile.Filemode != git.FileModeBlob { if readmeFile.Size > 1024*1024 || readmeFile.Filemode != git.FileModeBlob {
ctx.Data["FileIsLarge"] = true ctx.Data["FileIsLarge"] = true
} else if blob, err := readmeFile.LookupBlob(); err != nil { } else if blob, err := readmeFile.LookupBlob(); err != nil {
log.Error("repo.Single(readmeFile.LookupBlob): %v", err) //log.Error("repo.Single(readmeFile.LookupBlob): %v", err)
ctx.Error(404) ctx.Handle(404, "repo.Single(readmeFile.LookupBlob)", err)
return return
} else { } else {
// current repo branch link // current repo branch link
@ -239,7 +239,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
params["branchname"], params["commitid"]) params["branchname"], params["commitid"])
if err != nil { if err != nil {
log.Error("repo.Single(GetCommit): %v", err) log.Error("repo.Single(GetCommit): %v", err)
ctx.Error(404) ctx.Handle(404, "repo.Single(GetCommit)", err)
return return
} }
ctx.Data["LastCommit"] = commit ctx.Data["LastCommit"] = commit
@ -275,7 +275,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
func Setting(ctx *middleware.Context, params martini.Params) { func Setting(ctx *middleware.Context, params martini.Params) {
if !ctx.Repo.IsOwner { if !ctx.Repo.IsOwner {
ctx.Error(404) ctx.Handle(404, "repo.Setting", nil)
return return
} }
@ -307,7 +307,7 @@ func Commits(ctx *middleware.Context, params martini.Params) {
ctx.Handle(200, "repo.Commits", err) ctx.Handle(200, "repo.Commits", err)
return return
} else if len(brs) == 0 { } else if len(brs) == 0 {
ctx.Error(404) ctx.Handle(404, "repo.Commits", nil)
return return
} }
@ -315,7 +315,7 @@ func Commits(ctx *middleware.Context, params martini.Params) {
commits, err := models.GetCommits(params["username"], commits, err := models.GetCommits(params["username"],
params["reponame"], params["branchname"]) params["reponame"], params["branchname"])
if err != nil { if err != nil {
ctx.Error(404) ctx.Handle(404, "repo.Commits", nil)
return return
} }
ctx.Data["Username"] = params["username"] ctx.Data["Username"] = params["username"]

View File

@ -301,7 +301,7 @@ func Activate(ctx *middleware.Context) {
if len(code) == 0 { if len(code) == 0 {
ctx.Data["IsActivatePage"] = true ctx.Data["IsActivatePage"] = true
if ctx.User.IsActive { if ctx.User.IsActive {
ctx.Error(404) ctx.Handle(404, "user.Activate", nil)
return return
} }
// Resend confirmation e-mail. // Resend confirmation e-mail.

View File

@ -0,0 +1,7 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container">
<h4>This page is not found !</h4>
<p>Application Version: {{AppVer}}</p>
</div>
{{template "base/footer" .}}

View File

@ -0,0 +1,7 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container">
<p>An error is occurred : {{.ErrorMsg}}</p>
<p>Application Version: {{AppVer}}</p>
</div>
{{template "base/footer" .}}