MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / recoveryMiddleware

Function recoveryMiddleware

backend/pkg/httpserver/middlewares_test.go:36–49  ·  view source on GitHub ↗

TODO: Move recoveryMiddleware into the lib directory to actually be used by the real server.

(next http.Handler)

Source from the content-addressed store, hash-verified

34
35// TODO: Move recoveryMiddleware into the lib directory to actually be used by the real server.
36func recoveryMiddleware(next http.Handler) http.Handler {
37 return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
38 defer func() {
39 if r := recover(); r != nil {
40 slog.ErrorContext(req.Context(), "Panic recovered", "error", r)
41
42 // Return an Internal Server Error (500)
43 http.Error(w, "Internal Server Error", http.StatusInternalServerError)
44 }
45 }()
46
47 next.ServeHTTP(w, req)
48 })
49}
50
51func TestMiddlewaresOrder(t *testing.T) {
52 count := 0

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected