Revert "Improve unhandled error handling in prod mode"
This reverts commit c2079276.
Showing
1 changed file
with
2 additions
and
20 deletions
| ... | @@ -368,8 +368,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) | ... | @@ -368,8 +368,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) |
| 368 | if _, ok := err.(middleware.HTTPException); ok { | 368 | if _, ok := err.(middleware.HTTPException); ok { |
| 369 | // catch intented errors, only for HTTP 4XX and 5XX | 369 | // catch intented errors, only for HTTP 4XX and 5XX |
| 370 | } else { | 370 | } else { |
| 371 | handler := p.getErrorHandler(fmt.Sprint(err)) | 371 | errstr := fmt.Sprint(err) |
| 372 | if ErrorsShow { | 372 | if handler, ok := middleware.ErrorMaps[errstr]; ok && ErrorsShow { |
| 373 | handler(rw, r) | 373 | handler(rw, r) |
| 374 | } else { | 374 | } else { |
| 375 | if !RecoverPanic { | 375 | if !RecoverPanic { |
| ... | @@ -865,24 +865,6 @@ Admin: | ... | @@ -865,24 +865,6 @@ Admin: |
| 865 | } | 865 | } |
| 866 | } | 866 | } |
| 867 | 867 | ||
| 868 | // there always should be error handler that sets error code accordingly for all unhandled errors | ||
| 869 | // in order to have custom UI for error page it's necessary to override "500" error | ||
| 870 | func (p *ControllerRegistor) getErrorHandler(errorCode string) func(rw http.ResponseWriter, r *http.Request) { | ||
| 871 | handler := middleware.SimpleServerError | ||
| 872 | ok := true | ||
| 873 | if errorCode != "" { | ||
| 874 | handler, ok = middleware.ErrorMaps[errorCode] | ||
| 875 | if !ok { | ||
| 876 | handler, ok = middleware.ErrorMaps["500"] | ||
| 877 | } | ||
| 878 | if !ok || handler == nil { | ||
| 879 | handler = middleware.SimpleServerError | ||
| 880 | } | ||
| 881 | } | ||
| 882 | |||
| 883 | return handler | ||
| 884 | } | ||
| 885 | |||
| 886 | //responseWriter is a wrapper for the http.ResponseWriter | 868 | //responseWriter is a wrapper for the http.ResponseWriter |
| 887 | //started set to true if response was written to then don't execute other handler | 869 | //started set to true if response was written to then don't execute other handler |
| 888 | type responseWriter struct { | 870 | type responseWriter struct { | ... | ... |
-
Please register or sign in to post a comment