From 495033b9779ef046bc61fa89ef7d8e54e6d001a9 Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 13 Dec 2013 21:25:25 +0800 Subject: [PATCH] fix #366 --- router.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/router.go b/router.go index c36db4fb..018bb0ad 100644 --- a/router.go +++ b/router.go @@ -369,12 +369,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) if _, ok := err.(middleware.HTTPException); ok { // catch intented errors, only for HTTP 4XX and 5XX } else { - if ErrorsShow { - handler := p.getErrorHandler(fmt.Sprint(err)) - handler(rw, r) - } else { + if RunMode == "dev" { if !RecoverPanic { - // go back to panic panic(err) } else { var stack string @@ -385,15 +381,30 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) break } Critical(file, line) - if RunMode == "dev" { - stack = stack + fmt.Sprintln(file, line) - } + stack = stack + fmt.Sprintln(file, line) } - if RunMode == "dev" { - middleware.ShowErr(err, rw, r, stack) + middleware.ShowErr(err, rw, r, stack) + } + } else { + if ErrorsShow { + handler := p.getErrorHandler(fmt.Sprint(err)) + handler(rw, r) + } else { + if !RecoverPanic { + panic(err) + } else { + Critical("Handler crashed with error", err) + for i := 1; ; i++ { + _, file, line, ok := runtime.Caller(i) + if !ok { + break + } + Critical(file, line) + } } } } + } } }()