MCPcopy Create free account
hub / github.com/brimdata/super / panicCatchMiddleware

Function panicCatchMiddleware

service/middleware.go:77–95  ·  view source on GitHub ↗
(logger *zap.Logger)

Source from the content-addressed store, hash-verified

75}
76
77func panicCatchMiddleware(logger *zap.Logger) mux.MiddlewareFunc {
78 return func(next http.Handler) http.Handler {
79 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
80 defer func() {
81 rec := recover()
82 if rec == nil {
83 return
84 }
85 logger.DPanic("Panic",
86 zap.Error(srverr.RecoverError(rec)),
87 zap.String("request_id", api.RequestIDFromContext(r.Context())),
88 zap.Stack("stack"),
89 )
90 }()
91
92 next.ServeHTTP(w, r)
93 })
94 }
95}
96
97// recordingResponseWriter wraps an http.ResponseWriter to record the content
98// length and status code of the response.

Callers 1

NewCoreFunction · 0.85

Calls 6

RecoverErrorFunction · 0.92
RequestIDFromContextFunction · 0.92
ContextMethod · 0.80
ServeHTTPMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected