mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-21 12:44:49 -05:00
use ctx.Handle to handle 404 page
This commit is contained in:
parent
ad31893bbb
commit
47493a0191
5 changed files with 34 additions and 20 deletions
|
@ -36,7 +36,7 @@ func Issues(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
|
||||
if !ctx.Repo.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "issue.CreateIssue", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -65,14 +65,14 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
|
|||
func ViewIssue(ctx *middleware.Context, params martini.Params) {
|
||||
issueid, err := base.StrTo(params["issueid"]).Int()
|
||||
if err != nil {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "issue.ViewIssue", err)
|
||||
return
|
||||
}
|
||||
|
||||
issue, err := models.GetIssueById(int64(issueid))
|
||||
if err != nil {
|
||||
if err == models.ErrIssueNotExist {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "issue.ViewIssue", err)
|
||||
} else {
|
||||
ctx.Handle(200, "issue.ViewIssue", err)
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ func Branches(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Handle(200, "repo.Branches", err)
|
||||
return
|
||||
} else if len(brs) == 0 {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "repo.Branches", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -123,8 +123,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
|||
// Branches.
|
||||
brs, err := models.GetBranches(params["username"], params["reponame"])
|
||||
if err != nil {
|
||||
log.Error("repo.Single(GetBranches): %v", err)
|
||||
ctx.Error(404)
|
||||
//log.Error("repo.Single(GetBranches): %v", err)
|
||||
ctx.Handle(404, "repo.Single(GetBranches)", err)
|
||||
return
|
||||
} else if ctx.Repo.Repository.IsBare {
|
||||
ctx.Data["IsBareRepo"] = true
|
||||
|
@ -138,15 +138,15 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
|||
params["branchname"], params["commitid"], treename)
|
||||
|
||||
if err != nil && err != models.ErrRepoFileNotExist {
|
||||
log.Error("repo.Single(GetTargetFile): %v", err)
|
||||
ctx.Error(404)
|
||||
//log.Error("repo.Single(GetTargetFile): %v", err)
|
||||
ctx.Handle(404, "repo.Single(GetTargetFile)", err)
|
||||
return
|
||||
}
|
||||
|
||||
branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"]
|
||||
|
||||
if len(treename) != 0 && repoFile == nil {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "repo.Single", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -154,8 +154,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
|||
if repoFile.Size > 1024*1024 || repoFile.Filemode != git.FileModeBlob {
|
||||
ctx.Data["FileIsLarge"] = true
|
||||
} else if blob, err := repoFile.LookupBlob(); err != nil {
|
||||
log.Error("repo.Single(repoFile.LookupBlob): %v", err)
|
||||
ctx.Error(404)
|
||||
//log.Error("repo.Single(repoFile.LookupBlob): %v", err)
|
||||
ctx.Handle(404, "repo.Single(repoFile.LookupBlob)", err)
|
||||
} else {
|
||||
ctx.Data["IsFile"] = true
|
||||
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"],
|
||||
params["branchname"], params["commitid"], treename)
|
||||
if err != nil {
|
||||
log.Error("repo.Single(GetReposFiles): %v", err)
|
||||
ctx.Error(404)
|
||||
//log.Error("repo.Single(GetReposFiles): %v", err)
|
||||
ctx.Handle(404, "repo.Single(GetReposFiles)", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -203,8 +203,8 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
|||
if readmeFile.Size > 1024*1024 || readmeFile.Filemode != git.FileModeBlob {
|
||||
ctx.Data["FileIsLarge"] = true
|
||||
} else if blob, err := readmeFile.LookupBlob(); err != nil {
|
||||
log.Error("repo.Single(readmeFile.LookupBlob): %v", err)
|
||||
ctx.Error(404)
|
||||
//log.Error("repo.Single(readmeFile.LookupBlob): %v", err)
|
||||
ctx.Handle(404, "repo.Single(readmeFile.LookupBlob)", err)
|
||||
return
|
||||
} else {
|
||||
// current repo branch link
|
||||
|
@ -239,7 +239,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
|
|||
params["branchname"], params["commitid"])
|
||||
if err != nil {
|
||||
log.Error("repo.Single(GetCommit): %v", err)
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "repo.Single(GetCommit)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["LastCommit"] = commit
|
||||
|
@ -275,7 +275,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
|
|||
|
||||
func Setting(ctx *middleware.Context, params martini.Params) {
|
||||
if !ctx.Repo.IsOwner {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "repo.Setting", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ func Commits(ctx *middleware.Context, params martini.Params) {
|
|||
ctx.Handle(200, "repo.Commits", err)
|
||||
return
|
||||
} else if len(brs) == 0 {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "repo.Commits", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ func Commits(ctx *middleware.Context, params martini.Params) {
|
|||
commits, err := models.GetCommits(params["username"],
|
||||
params["reponame"], params["branchname"])
|
||||
if err != nil {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "repo.Commits", nil)
|
||||
return
|
||||
}
|
||||
ctx.Data["Username"] = params["username"]
|
||||
|
|
|
@ -301,7 +301,7 @@ func Activate(ctx *middleware.Context) {
|
|||
if len(code) == 0 {
|
||||
ctx.Data["IsActivatePage"] = true
|
||||
if ctx.User.IsActive {
|
||||
ctx.Error(404)
|
||||
ctx.Handle(404, "user.Activate", nil)
|
||||
return
|
||||
}
|
||||
// Resend confirmation e-mail.
|
||||
|
|
7
templates/status/404.tmpl
Normal file
7
templates/status/404.tmpl
Normal 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" .}}
|
7
templates/status/500.tmpl
Normal file
7
templates/status/500.tmpl
Normal 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" .}}
|
Loading…
Reference in a new issue