diff --git a/errors.go b/errors.go
new file mode 100644
index 00000000..4cd6534c
--- /dev/null
+++ b/errors.go
@@ -0,0 +1,70 @@
+package beego
+
+import (
+ "fmt"
+ "html/template"
+ "net/http"
+ "runtime"
+)
+
+var tpl = `
+
+
+
+
+ beego application error
+
+
+
+
+
+
+
+
+ Request Method: | {{.RequestMethod}} |
+
+
+ Request URL: | {{.RequestURL}} |
+
+
+ RemoteAddr: | {{.RemoteAddr }} |
+
+
+
+
+
+
+
+`
+
+func ShowErr(err interface{}, rw http.ResponseWriter, r *http.Request, Stack string) {
+ t, err := template.New("beegoerrortemp").Parse(tpl)
+ data := make(map[string]string)
+ data["AppError"] = AppName + ":" + fmt.Sprint(err)
+ data["RequestMethod"] = r.Method
+ data["RequestURL"] = r.RequestURI
+ data["RemoteAddr"] = r.RemoteAddr
+ data["Stack"] = Stack
+ data["BeegoVersion"] = VERSION
+ data["GoVersion"] = runtime.Version()
+ t.Execute(rw, data)
+}
diff --git a/router.go b/router.go
index f06b4b7d..9129ddc5 100644
--- a/router.go
+++ b/router.go
@@ -1,6 +1,7 @@
package beego
import (
+ "fmt"
"net/http"
"net/url"
"reflect"
@@ -190,13 +191,20 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
// go back to panic
panic(err)
} else {
+ var stack string
Critical("Handler crashed with error", err)
- for i := 1; ; i += 1 {
+ for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
Critical(file, line)
+ if RunMode == "dev" {
+ stack = stack + fmt.Sprintln(file, line)
+ }
+ }
+ if RunMode == "dev" {
+ ShowErr(err, rw, r, stack)
}
}
}