Commit 26130a5d authored by astaxie's avatar astaxie

fix #1073

parent 2c9363d2
...@@ -439,24 +439,26 @@ func exception(errcode string, ctx *context.Context) { ...@@ -439,24 +439,26 @@ func exception(errcode string, ctx *context.Context) {
if err != nil { if err != nil {
code = 503 code = 503
} }
ctx.ResponseWriter.WriteHeader(code)
if h, ok := ErrorMaps[errcode]; ok { if h, ok := ErrorMaps[errcode]; ok {
executeError(h, ctx) executeError(h, ctx, code)
return return
} else if h, ok := ErrorMaps["503"]; ok { } else if h, ok := ErrorMaps["503"]; ok {
executeError(h, ctx) executeError(h, ctx, code)
return return
} else { } else {
ctx.ResponseWriter.WriteHeader(code)
ctx.WriteString(errcode) ctx.WriteString(errcode)
} }
} }
func executeError(err *errorInfo, ctx *context.Context) { func executeError(err *errorInfo, ctx *context.Context, code int) {
if err.errorType == errorTypeHandler { if err.errorType == errorTypeHandler {
ctx.ResponseWriter.WriteHeader(code)
err.handler(ctx.ResponseWriter, ctx.Request) err.handler(ctx.ResponseWriter, ctx.Request)
return return
} }
if err.errorType == errorTypeController { if err.errorType == errorTypeController {
ctx.Output.SetStatus(code)
//Invoke the request handler //Invoke the request handler
vc := reflect.New(err.controllerType) vc := reflect.New(err.controllerType)
execController, ok := vc.Interface().(ControllerInterface) execController, ok := vc.Interface().(ControllerInterface)
...@@ -476,11 +478,9 @@ func executeError(err *errorInfo, ctx *context.Context) { ...@@ -476,11 +478,9 @@ func executeError(err *errorInfo, ctx *context.Context) {
method.Call(in) method.Call(in)
//render template //render template
if ctx.Output.Status == 0 { if AutoRender {
if AutoRender { if err := execController.Render(); err != nil {
if err := execController.Render(); err != nil { panic(err)
panic(err)
}
} }
} }
......
...@@ -862,8 +862,8 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) { ...@@ -862,8 +862,8 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
panic(err) panic(err)
} else { } else {
if ErrorsShow { if ErrorsShow {
if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok { if _, ok := ErrorMaps[fmt.Sprint(err)]; ok {
executeError(handler, context) exception(fmt.Sprint(err), context)
return return
} }
} }
...@@ -886,15 +886,7 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) { ...@@ -886,15 +886,7 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
} else { } else {
// in production model show all infomation // in production model show all infomation
if ErrorsShow { if ErrorsShow {
if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok { exception(fmt.Sprint(err), context)
executeError(handler, context)
return
} else if handler, ok := ErrorMaps["503"]; ok {
executeError(handler, context)
return
} else {
context.WriteString(fmt.Sprint(err))
}
} else { } else {
Critical("the request url is ", context.Input.Url()) Critical("the request url is ", context.Input.Url())
Critical("Handler crashed with error", err) Critical("Handler crashed with error", err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment