aboutsummaryrefslogtreecommitdiff
path: root/modules/log
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-14 01:40:34 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-14 01:40:34 -0400
commit56cf05be771977abd9ae2e68dd446092c595981c (patch)
tree49e4bb385f199c0ec8ec6684256b340927d9565e /modules/log
parent47edf7f4f9d359765764207cbcb6dd82dba36de8 (diff)
Add errHandler mid ware
Diffstat (limited to 'modules/log')
-rw-r--r--modules/log/error.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/log/error.go b/modules/log/error.go
new file mode 100644
index 00000000..cb94ec24
--- /dev/null
+++ b/modules/log/error.go
@@ -0,0 +1,32 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package log
+
+import (
+ "github.com/codegangsta/martini"
+ "github.com/martini-contrib/render"
+)
+
+// ErrHandler is an interface for custom error handler.
+type ErrHandler interface {
+ Handle(string, render.Render, error)
+}
+
+// ErrHandle is a Middleware that maps a ErrHandler service into the Martini handler chain.
+func ErrHandle() martini.Handler {
+ return func(context martini.Context) {
+ context.MapTo(&errHandler{}, (*ErrHandler)(nil))
+ }
+}
+
+type errHandler struct {
+}
+
+func (eh *errHandler) Handle(title string, r render.Render, err error) {
+ Error("%s: %v", title, err)
+ r.HTML(200, "base/error", map[string]interface{}{
+ "ErrorMsg": err,
+ })
+}