diff --git a/http/sentryhttp.go b/http/sentryhttp.go index b8071648e..87b760cc8 100644 --- a/http/sentryhttp.go +++ b/http/sentryhttp.go @@ -50,22 +50,16 @@ func New(options Options) *Handler { // Handle wraps http.Handler and recovers from caught panics. func (h *Handler) Handle(handler http.Handler) http.Handler { - return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - ctx := r.Context() - hub := sentry.GetHubFromContext(ctx) - if hub == nil { - hub = sentry.CurrentHub().Clone() - } - hub.Scope().SetRequest(r) - ctx = sentry.SetHubOnContext(ctx, hub) - defer h.recoverWithSentry(hub, r) - handler.ServeHTTP(rw, r.WithContext(ctx)) - }) + return h.handle(handler) } -// HandleFunc wraps http.HandleFunc and recovers from caught panics. +// Deprecated: Use the Handle method instead. func (h *Handler) HandleFunc(handler http.HandlerFunc) http.HandlerFunc { - return func(rw http.ResponseWriter, r *http.Request) { + return h.handle(handler) +} + +func (h *Handler) handle(handler http.Handler) http.HandlerFunc { + return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { ctx := r.Context() hub := sentry.GetHubFromContext(ctx) if hub == nil { @@ -74,8 +68,8 @@ func (h *Handler) HandleFunc(handler http.HandlerFunc) http.HandlerFunc { hub.Scope().SetRequest(r) ctx = sentry.SetHubOnContext(ctx, hub) defer h.recoverWithSentry(hub, r) - handler(rw, r.WithContext(ctx)) - } + handler.ServeHTTP(rw, r.WithContext(ctx)) + }) } func (h *Handler) recoverWithSentry(hub *sentry.Hub, r *http.Request) {