Skip to content

Log status 500 for a request whose handler raised - #55

Merged
thomas-samoht merged 3 commits into
feat/replace-update-context-with-set-contextfrom
fix/access-status-500-on-crash
Nov 10, 2026
Merged

thomas-samoht merged 3 commits into
feat/replace-update-context-with-set-contextfrom
fix/access-status-500-on-crash

Conversation

@thomas-samoht

Copy link
Copy Markdown
Contributor

No description provided.

@thomas-samoht
thomas-samoht requested a review from a team as a code owner November 5, 2026 09:41
Comment thread tests/test_middleware.py Resolved
Comment thread gfmodules/logging/middleware.py Resolved
ricklambrechts
ricklambrechts previously approved these changes Nov 9, 2026
@thomas-samoht
thomas-samoht force-pushed the fix/access-status-500-on-crash branch from e9df736 to 81d30bd Compare November 9, 2026 15:57
@thomas-samoht
thomas-samoht changed the base branch from main to feat/replace-update-context-with-set-context November 9, 2026 15:57
@thomas-samoht
thomas-samoht added this pull request to stack #61 November 9, 2026 15:57
Comment thread docs/STARTING_GUIDE.md Resolved
@thomas-samoht
thomas-samoht force-pushed the fix/access-status-500-on-crash branch 9 times, most recently from 6d00f82 to 8269ec5 Compare November 10, 2026 09:19
ricklambrechts
ricklambrechts previously approved these changes Nov 10, 2026
Problem: when the handler raised, call_next() raised too and the access
record was logged with status_code null. The client still received an
answer, the 500 that Starlette's ServerErrorMiddleware sends for an
unhandled exception, but the access record did not say so. Anything
counting server errors on the app stream missed exactly the requests
that crashed.

Fix: the access record carries 500 when there is no response. The
middleware is meant to be added last, so ServerErrorMiddleware is the
only layer outside it, and that is the status it sends. An exception
handler registered for Exception may answer with another status, which
the middleware cannot see, as the exception leaves it before the handler
runs. The test that pinned null now expects the 500 the client gets.
@thomas-samoht
thomas-samoht merged commit 180329c into main Nov 10, 2026
14 of 25 checks passed
@thomas-samoht
thomas-samoht deleted the fix/access-status-500-on-crash branch November 10, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants