A handler's panic is logged and counted as 500 (closes #125)
check / check (push) Waiting to run
check / check (push) Waiting to run
Recoverer comes first, so it wrote the 500 only after the panic had passed the request log and the metrics, which both recorded 200. Write500OnPanic, placed after the request log and after the metrics, writes the 500 as the panic passes and panics again, so Sentry and Recoverer still get it. Recoverer now writes its 500 only when no status was written, so the server logs no superfluous WriteHeader call. The test also requires Recoverer's log line for the handler's panic, so it fails if Write500OnPanic stops passing the panic on. Model: opus-5-5
This commit was merged in pull request #133.
This commit is contained in:
@@ -34,13 +34,16 @@ func (s *Server) SetupRoutes() {
|
||||
s.router.Use(s.mw.Recoverer())
|
||||
s.router.Use(middleware.RequestID)
|
||||
s.router.Use(s.mw.Logging())
|
||||
// s.mw.Recoverer would write a panic's 500 only after the panic has
|
||||
// passed the request log, so it is written here, where the log sees it.
|
||||
s.router.Use(s.mw.Write500OnPanic())
|
||||
s.router.Use(s.mw.SecurityHeaders())
|
||||
s.router.Use(s.mw.CORS(s.params.Config.CORSAllowedOrigins))
|
||||
s.router.Use(s.mw.MaxBodyBytes(maxRequestBodyBytes))
|
||||
s.router.Use(middleware.Timeout(requestTimeout))
|
||||
|
||||
// Sentry reports a panic, then panics again, so that s.mw.Recoverer
|
||||
// still answers 500.
|
||||
// Sentry reports a panic, then panics again, so that it still
|
||||
// reaches s.mw.Recoverer.
|
||||
if s.params.Config.SentryDSN != "" {
|
||||
s.router.Use(sentryhttp.New(sentryhttp.Options{Repanic: true}).Handle)
|
||||
}
|
||||
@@ -64,6 +67,8 @@ func (s *Server) SetupRoutes() {
|
||||
// other.
|
||||
if s.params.Config.MetricsUsername != "" {
|
||||
r.Use(s.mw.Metrics(registry))
|
||||
// Likewise inside the metrics.
|
||||
r.Use(s.mw.Write500OnPanic())
|
||||
}
|
||||
|
||||
r.Get("/.well-known/healthcheck", s.h.HandleHealthCheck())
|
||||
|
||||
Reference in New Issue
Block a user