TODO: Move recoveryMiddleware into the lib directory to actually be used by the real server.
(next http.Handler)
| 34 | |
| 35 | // TODO: Move recoveryMiddleware into the lib directory to actually be used by the real server. |
| 36 | func 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 | |
| 51 | func TestMiddlewaresOrder(t *testing.T) { |
| 52 | count := 0 |