Report handler panics through the logger and answer 500 (closes #187)
All checks were successful
check / check (push) Successful in 2m50s
All checks were successful
check / check (push) Successful in 2m50s
This commit was merged in pull request #189.
This commit is contained in:
@@ -54,3 +54,40 @@ func NewRouterForTest(
|
||||
|
||||
return s.router
|
||||
}
|
||||
|
||||
// ProbePattern is the route NewRouterWithProbeForTest adds to the
|
||||
// production route tree.
|
||||
const ProbePattern = "/probe"
|
||||
|
||||
// NewRouterWithProbeForTest builds the production route tree exactly
|
||||
// as NewRouterForTest does and then registers probe at ProbePattern,
|
||||
// so a test can drive a handler that panics through the shipped
|
||||
// global middleware chain rather than a hand-assembled one. Nothing
|
||||
// about the chain is rebuilt here: the probe is an extra leaf under
|
||||
// the same Use() registrations every other route gets.
|
||||
//
|
||||
// sentryEnabled selects whether the sentryhttp handler is registered,
|
||||
// which in production a configured SENTRY_DSN decides. It is a
|
||||
// parameter because the relationship between that handler's Repanic
|
||||
// option and the recoverer registered outside it is the thing a test
|
||||
// has to be able to pin.
|
||||
func NewRouterWithProbeForTest(
|
||||
log *slog.Logger,
|
||||
cfg *config.Config,
|
||||
mw *middleware.Middleware,
|
||||
h *handlers.Handlers,
|
||||
sentryEnabled bool,
|
||||
probe http.HandlerFunc,
|
||||
) http.Handler {
|
||||
s := &Server{
|
||||
log: log,
|
||||
mw: mw,
|
||||
h: h,
|
||||
params: ServerParams{Config: cfg},
|
||||
sentryEnabled: sentryEnabled,
|
||||
}
|
||||
s.SetupRoutes()
|
||||
s.router.Handle(ProbePattern, probe)
|
||||
|
||||
return s.router
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user