ServeHTTP implements the http.Handler interface.
(w http.ResponseWriter, r *http.Request)
| 749 | |
| 750 | // ServeHTTP implements the http.Handler interface. |
| 751 | func (h errorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 752 | // Keep track of whether a response gets written. |
| 753 | lw, ok := w.(*loggingResponseWriter) |
| 754 | if !ok { |
| 755 | lw = newLogResponseWriter(h.opts.Logf, w, r) |
| 756 | } |
| 757 | |
| 758 | var err error |
| 759 | defer func() { |
| 760 | // In case the handler panics, we want to recover and continue logging |
| 761 | // the error before logging it (or re-panicking if we couldn't log). |
| 762 | rec := recover() |
| 763 | if rec != nil { |
| 764 | err = panic2err(rec) |
| 765 | } |
| 766 | if err == nil { |
| 767 | return |
| 768 | } |
| 769 | if h.handleError(w, r, lw, err) { |
| 770 | return |
| 771 | } |
| 772 | if rec != nil { |
| 773 | // If we weren't able to log the panic somewhere, throw it up the |
| 774 | // stack to someone who can. |
| 775 | panic(rec) |
| 776 | } |
| 777 | }() |
| 778 | err = h.rh.ServeHTTPReturn(lw, r) |
| 779 | } |
| 780 | |
| 781 | func (h errorHandler) handleError(w http.ResponseWriter, r *http.Request, lw *loggingResponseWriter, err error) bool { |
| 782 | var logged bool |
nothing calls this directly
no test coverage detected