aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-10 16:05:11 -0500
committerUnknwon <u@gogs.io>2017-02-10 16:05:11 -0500
commit2c154ccbe7d3d4f038885eb439c36bb9fd533e53 (patch)
tree62533f64017790da6421f75a702d7f8196ee6b29
parent3f95824e656f2eb6a193038d58316b5abf0b1888 (diff)
Minor improve on error handling
-rw-r--r--gogs.go2
-rw-r--r--modules/context/context.go16
-rw-r--r--modules/context/repo.go14
-rw-r--r--modules/setting/setting.go4
-rw-r--r--routers/install.go3
-rw-r--r--templates/.VERSION2
6 files changed, 22 insertions, 19 deletions
diff --git a/gogs.go b/gogs.go
index 42ddaaef..5ca4b68c 100644
--- a/gogs.go
+++ b/gogs.go
@@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
-const APP_VER = "0.9.139.0209"
+const APP_VER = "0.9.139.0210"
func init() {
setting.AppVer = APP_VER
diff --git a/modules/context/context.go b/modules/context/context.go
index a9a5e270..e90d5f00 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -89,22 +89,24 @@ func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}
// Handle handles and logs error by given status.
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 {
case 404:
ctx.Data["Title"] = "Page Not Found"
case 500:
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)))
}
+// NotFound simply renders the 404 page.
+func (ctx *Context) NotFound() {
+ ctx.Handle(404, "", nil)
+}
+
// NotFoundOrServerError use error check function to determine if the 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.
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 1c322a95..b72d19ec 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -164,7 +164,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
earlyResponseForGoGetMeta(ctx)
return
}
- ctx.Handle(404, "GetUserByName", err)
+ ctx.NotFound()
} else {
ctx.Handle(500, "GetUserByName", err)
}
@@ -182,7 +182,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
earlyResponseForGoGetMeta(ctx)
return
}
- ctx.Handle(404, "GetRepositoryByName", err)
+ ctx.NotFound()
} else {
ctx.Handle(500, "GetRepositoryByName", err)
}
@@ -210,7 +210,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
earlyResponseForGoGetMeta(ctx)
return
}
- ctx.Handle(404, "no access right", err)
+ ctx.NotFound()
return
}
ctx.Data["HasAccess"] = true
@@ -395,7 +395,7 @@ func RepoRef() macaron.Handler {
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
if err != nil {
- ctx.Handle(404, "GetCommit", nil)
+ ctx.NotFound()
return
}
} else {
@@ -455,7 +455,7 @@ func RepoRef() macaron.Handler {
func RequireRepoAdmin() macaron.Handler {
return func(ctx *Context) {
if !ctx.IsSigned || (!ctx.Repo.IsAdmin() && !ctx.User.IsAdmin) {
- ctx.Handle(404, ctx.Req.RequestURI, nil)
+ ctx.NotFound()
return
}
}
@@ -464,7 +464,7 @@ func RequireRepoAdmin() macaron.Handler {
func RequireRepoWriter() macaron.Handler {
return func(ctx *Context) {
if !ctx.IsSigned || (!ctx.Repo.IsWriter() && !ctx.User.IsAdmin) {
- ctx.Handle(404, ctx.Req.RequestURI, nil)
+ ctx.NotFound()
return
}
}
@@ -474,7 +474,7 @@ func RequireRepoWriter() macaron.Handler {
func GitHookService() macaron.Handler {
return func(ctx *Context) {
if !ctx.User.CanEditGitHook() {
- ctx.Handle(404, "GitHookService", nil)
+ ctx.NotFound()
return
}
}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 4db8dbff..ac4a893b 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -620,8 +620,8 @@ func newService() {
func newLogService() {
if len(BuildTime) > 0 {
- log.Info("Build Time: %s", BuildTime)
- log.Info("Build Git Hash: %s", BuildGitHash)
+ log.Trace("Build Time: %s", BuildTime)
+ log.Trace("Build Git Hash: %s", BuildGitHash)
}
// Because we always create a console logger as primary logger before all settings are loaded,
diff --git a/routers/install.go b/routers/install.go
index a44ae8eb..c078d1ff 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -87,7 +87,8 @@ func GlobalInit() {
if setting.InstallLock && setting.SSH.StartBuiltinServer {
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)
}
}
diff --git a/templates/.VERSION b/templates/.VERSION
index 5134f69e..694d35dd 100644
--- a/templates/.VERSION
+++ b/templates/.VERSION
@@ -1 +1 @@
-0.9.139.0209 \ No newline at end of file
+0.9.139.0210 \ No newline at end of file