mirror of
https://github.com/gogs/gogs.git
synced 2025-12-22 16:20:14 +01:00
Minor improve on error handling
This commit is contained in:
2
gogs.go
2
gogs.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.9.139.0209"
|
const APP_VER = "0.9.139.0210"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|||||||
@@ -89,22 +89,24 @@ func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}
|
|||||||
|
|
||||||
// Handle handles and logs error by given status.
|
// Handle handles and logs error by given status.
|
||||||
func (ctx *Context) Handle(status int, title string, err error) {
|
func (ctx *Context) Handle(status int, title string, err error) {
|
||||||
if err != nil {
|
|
||||||
log.Error(4, "%s: %v", title, err)
|
|
||||||
if macaron.Env != macaron.PROD {
|
|
||||||
ctx.Data["ErrorMsg"] = err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch status {
|
switch status {
|
||||||
case 404:
|
case 404:
|
||||||
ctx.Data["Title"] = "Page Not Found"
|
ctx.Data["Title"] = "Page Not Found"
|
||||||
case 500:
|
case 500:
|
||||||
ctx.Data["Title"] = "Internal Server Error"
|
ctx.Data["Title"] = "Internal Server Error"
|
||||||
|
log.Error(4, "%s: %v", title, err)
|
||||||
|
if !setting.ProdMode || (ctx.IsSigned && ctx.User.IsAdmin) {
|
||||||
|
ctx.Data["ErrorMsg"] = err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status)))
|
ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotFound simply renders the 404 page.
|
||||||
|
func (ctx *Context) NotFound() {
|
||||||
|
ctx.Handle(404, "", nil)
|
||||||
|
}
|
||||||
|
|
||||||
// NotFoundOrServerError use error check function to determine if the error
|
// NotFoundOrServerError use error check function to determine if the error
|
||||||
// is about not found. It responses with 404 status code for not found error,
|
// is about not found. It responses with 404 status code for not found error,
|
||||||
// or error context description for logging purpose of 500 server error.
|
// or error context description for logging purpose of 500 server error.
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
|
|||||||
earlyResponseForGoGetMeta(ctx)
|
earlyResponseForGoGetMeta(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Handle(404, "GetUserByName", err)
|
ctx.NotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetUserByName", err)
|
ctx.Handle(500, "GetUserByName", err)
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
|
|||||||
earlyResponseForGoGetMeta(ctx)
|
earlyResponseForGoGetMeta(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Handle(404, "GetRepositoryByName", err)
|
ctx.NotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetRepositoryByName", err)
|
ctx.Handle(500, "GetRepositoryByName", err)
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
|
|||||||
earlyResponseForGoGetMeta(ctx)
|
earlyResponseForGoGetMeta(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Handle(404, "no access right", err)
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["HasAccess"] = true
|
ctx.Data["HasAccess"] = true
|
||||||
@@ -395,7 +395,7 @@ func RepoRef() macaron.Handler {
|
|||||||
|
|
||||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(404, "GetCommit", nil)
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -455,7 +455,7 @@ func RepoRef() macaron.Handler {
|
|||||||
func RequireRepoAdmin() macaron.Handler {
|
func RequireRepoAdmin() macaron.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
if !ctx.IsSigned || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) {
|
if !ctx.IsSigned || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) {
|
||||||
ctx.Handle(404, ctx.Req.RequestURI, nil)
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -464,7 +464,7 @@ func RequireRepoAdmin() macaron.Handler {
|
|||||||
func RequireRepoWriter() macaron.Handler {
|
func RequireRepoWriter() macaron.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
if !ctx.IsSigned || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) {
|
if !ctx.IsSigned || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) {
|
||||||
ctx.Handle(404, ctx.Req.RequestURI, nil)
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -474,7 +474,7 @@ func RequireRepoWriter() macaron.Handler {
|
|||||||
func GitHookService() macaron.Handler {
|
func GitHookService() macaron.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
if !ctx.User.CanEditGitHook() {
|
if !ctx.User.CanEditGitHook() {
|
||||||
ctx.Handle(404, "GitHookService", nil)
|
ctx.NotFound()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -620,8 +620,8 @@ func newService() {
|
|||||||
|
|
||||||
func newLogService() {
|
func newLogService() {
|
||||||
if len(BuildTime) > 0 {
|
if len(BuildTime) > 0 {
|
||||||
log.Info("Build Time: %s", BuildTime)
|
log.Trace("Build Time: %s", BuildTime)
|
||||||
log.Info("Build Git Hash: %s", BuildGitHash)
|
log.Trace("Build Git Hash: %s", BuildGitHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because we always create a console logger as primary logger before all settings are loaded,
|
// Because we always create a console logger as primary logger before all settings are loaded,
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ func GlobalInit() {
|
|||||||
|
|
||||||
if setting.InstallLock && setting.SSH.StartBuiltinServer {
|
if setting.InstallLock && setting.SSH.StartBuiltinServer {
|
||||||
ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers)
|
ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers)
|
||||||
log.Info("SSH server started on %s:%v. Cipher list (%v)", setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers)
|
log.Info("SSH server started on %s:%v", setting.SSH.ListenHost, setting.SSH.ListenPort)
|
||||||
|
log.Trace("SSH server cipher list: %v", setting.SSH.ServerCiphers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.9.139.0209
|
0.9.139.0210
|
||||||
Reference in New Issue
Block a user