fda84120 by astaxie

fix #893

1 parent 57e62e5e
...@@ -31,6 +31,7 @@ import ( ...@@ -31,6 +31,7 @@ import (
31 "strings" 31 "strings"
32 "time" 32 "time"
33 33
34 "github.com/astaxie/beego"
34 "github.com/astaxie/beego/middleware" 35 "github.com/astaxie/beego/middleware"
35 "github.com/astaxie/beego/utils" 36 "github.com/astaxie/beego/utils"
36 ) 37 )
...@@ -69,7 +70,8 @@ func (ctx *Context) Abort(status int, body string) { ...@@ -69,7 +70,8 @@ func (ctx *Context) Abort(status int, body string) {
69 panic(e) 70 panic(e)
70 } 71 }
71 // last panic user string 72 // last panic user string
72 panic(body) 73 ctx.ResponseWriter.Write([]byte(body))
74 panic(beego.USERSTOPRUN)
73 } 75 }
74 76
75 // Write string to response body. 77 // Write string to response body.
......
...@@ -831,7 +831,9 @@ func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Reques ...@@ -831,7 +831,9 @@ func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Reques
831 if err == USERSTOPRUN { 831 if err == USERSTOPRUN {
832 return 832 return
833 } 833 }
834 if _, ok := err.(middleware.HTTPException); ok { 834 if he, ok := err.(middleware.HTTPException); ok {
835 rw.WriteHeader(he.StatusCode)
836 rw.Write([]byte(he.Description))
835 // catch intented errors, only for HTTP 4XX and 5XX 837 // catch intented errors, only for HTTP 4XX and 5XX
836 } else { 838 } else {
837 if RunMode == "dev" { 839 if RunMode == "dev" {
...@@ -863,9 +865,10 @@ func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Reques ...@@ -863,9 +865,10 @@ func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Reques
863 } else { 865 } else {
864 // in production model show all infomation 866 // in production model show all infomation
865 if ErrorsShow { 867 if ErrorsShow {
866 handler := p.getErrorHandler(fmt.Sprint(err)) 868 if handler, ok := middleware.ErrorMaps[fmt.Sprint(err)]; ok {
867 handler(rw, r) 869 handler(rw, r)
868 return 870 return
871 }
869 } else { 872 } else {
870 Critical("the request url is ", r.URL.Path) 873 Critical("the request url is ", r.URL.Path)
871 Critical("Handler crashed with error", err) 874 Critical("Handler crashed with error", err)
...@@ -884,24 +887,6 @@ func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Reques ...@@ -884,24 +887,6 @@ func (p *ControllerRegistor) recoverPanic(rw http.ResponseWriter, r *http.Reques
884 } 887 }
885 } 888 }
886 889
887 // there always should be error handler that sets error code accordingly for all unhandled errors.
888 // in order to have custom UI for error page it's necessary to override "500" error.
889 func (p *ControllerRegistor) getErrorHandler(errorCode string) func(rw http.ResponseWriter, r *http.Request) {
890 handler := middleware.SimpleServerError
891 ok := true
892 if errorCode != "" {
893 handler, ok = middleware.ErrorMaps[errorCode]
894 if !ok {
895 handler, ok = middleware.ErrorMaps["500"]
896 }
897 if !ok || handler == nil {
898 handler = middleware.SimpleServerError
899 }
900 }
901
902 return handler
903 }
904
905 //responseWriter is a wrapper for the http.ResponseWriter 890 //responseWriter is a wrapper for the http.ResponseWriter
906 //started set to true if response was written to then don't execute other handler 891 //started set to true if response was written to then don't execute other handler
907 type responseWriter struct { 892 type responseWriter struct {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!