1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-04 09:30:17 +00:00
This commit is contained in:
astaxie
2013-05-07 00:17:25 +08:00
parent 93babc5780
commit 1e7c1a265e
5 changed files with 1290 additions and 1015 deletions

View File

@ -187,25 +187,30 @@ func (p *ControllerRegistor) FilterPrefixPath(path string, filter http.HandlerFu
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
if !RecoverPanic {
// go back to panic
panic(err)
errstr := fmt.Sprint(err)
if handler, ok := ErrorMaps[errstr]; ok {
handler(rw, r)
} else {
var stack string
Critical("Handler crashed with error", err)
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
if !RecoverPanic {
// go back to panic
panic(err)
} else {
var stack string
Critical("Handler crashed with error", err)
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)
}
}
Critical(file, line)
if RunMode == "dev" {
stack = stack + fmt.Sprintln(file, line)
ShowErr(err, rw, r, stack)
}
}
if RunMode == "dev" {
ShowErr(err, rw, r, stack)
}
}
}
}()
@ -385,7 +390,11 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
//if no matches to url, throw a not found exception
if w.started == false {
http.NotFound(w, r)
if h, ok := ErrorMaps["404"]; ok {
h(w, r)
} else {
http.NotFound(w, r)
}
}
}