26130a5d by astaxie

fix #1073

1 parent 2c9363d2
...@@ -439,24 +439,26 @@ func exception(errcode string, ctx *context.Context) { ...@@ -439,24 +439,26 @@ func exception(errcode string, ctx *context.Context) {
439 if err != nil { 439 if err != nil {
440 code = 503 440 code = 503
441 } 441 }
442 ctx.ResponseWriter.WriteHeader(code)
443 if h, ok := ErrorMaps[errcode]; ok { 442 if h, ok := ErrorMaps[errcode]; ok {
444 executeError(h, ctx) 443 executeError(h, ctx, code)
445 return 444 return
446 } else if h, ok := ErrorMaps["503"]; ok { 445 } else if h, ok := ErrorMaps["503"]; ok {
447 executeError(h, ctx) 446 executeError(h, ctx, code)
448 return 447 return
449 } else { 448 } else {
449 ctx.ResponseWriter.WriteHeader(code)
450 ctx.WriteString(errcode) 450 ctx.WriteString(errcode)
451 } 451 }
452 } 452 }
453 453
454 func executeError(err *errorInfo, ctx *context.Context) { 454 func executeError(err *errorInfo, ctx *context.Context, code int) {
455 if err.errorType == errorTypeHandler { 455 if err.errorType == errorTypeHandler {
456 ctx.ResponseWriter.WriteHeader(code)
456 err.handler(ctx.ResponseWriter, ctx.Request) 457 err.handler(ctx.ResponseWriter, ctx.Request)
457 return 458 return
458 } 459 }
459 if err.errorType == errorTypeController { 460 if err.errorType == errorTypeController {
461 ctx.Output.SetStatus(code)
460 //Invoke the request handler 462 //Invoke the request handler
461 vc := reflect.New(err.controllerType) 463 vc := reflect.New(err.controllerType)
462 execController, ok := vc.Interface().(ControllerInterface) 464 execController, ok := vc.Interface().(ControllerInterface)
...@@ -476,13 +478,11 @@ func executeError(err *errorInfo, ctx *context.Context) { ...@@ -476,13 +478,11 @@ func executeError(err *errorInfo, ctx *context.Context) {
476 method.Call(in) 478 method.Call(in)
477 479
478 //render template 480 //render template
479 if ctx.Output.Status == 0 {
480 if AutoRender { 481 if AutoRender {
481 if err := execController.Render(); err != nil { 482 if err := execController.Render(); err != nil {
482 panic(err) 483 panic(err)
483 } 484 }
484 } 485 }
485 }
486 486
487 // finish all runrouter. release resource 487 // finish all runrouter. release resource
488 execController.Finish() 488 execController.Finish()
......
...@@ -862,8 +862,8 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) { ...@@ -862,8 +862,8 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
862 panic(err) 862 panic(err)
863 } else { 863 } else {
864 if ErrorsShow { 864 if ErrorsShow {
865 if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok { 865 if _, ok := ErrorMaps[fmt.Sprint(err)]; ok {
866 executeError(handler, context) 866 exception(fmt.Sprint(err), context)
867 return 867 return
868 } 868 }
869 } 869 }
...@@ -886,15 +886,7 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) { ...@@ -886,15 +886,7 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
886 } else { 886 } else {
887 // in production model show all infomation 887 // in production model show all infomation
888 if ErrorsShow { 888 if ErrorsShow {
889 if handler, ok := ErrorMaps[fmt.Sprint(err)]; ok { 889 exception(fmt.Sprint(err), context)
890 executeError(handler, context)
891 return
892 } else if handler, ok := ErrorMaps["503"]; ok {
893 executeError(handler, context)
894 return
895 } else {
896 context.WriteString(fmt.Sprint(err))
897 }
898 } else { 890 } else {
899 Critical("the request url is ", context.Input.Url()) 891 Critical("the request url is ", context.Input.Url())
900 Critical("Handler crashed with error", err) 892 Critical("Handler crashed with error", err)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!