Skip to content

Keep the real status code on rendered error pages - #465

Merged
Mariatta merged 1 commit into
mainfrom
error-status-codes
Oct 20, 2026
Merged

Mariatta merged 1 commit into
mainfrom
error-status-codes

Conversation

@Mariatta

Copy link
Copy Markdown
Member

Found while preparing the cabotage deployment (#464): over the socket, GET /nope answered 200 OK with the error page.

error_middleware catches every HTTPException, renders error.html, and returns it with the renderer's default status 200. That hides real errors from cabotage's probes, from anything watching response codes, and from Sentry.

Changes

  • Pass status=ex.status to render_template, so a 404 stays a 404 and the CSRF failure stays a 403. The page content is unchanged.
  • Let HTTPExceptions below 400 (redirects) pass through instead of being rendered as an error page. Nothing in the app raises one today, all redirects are returned, so this only guards against a future mistake.
  • Tests for the three cases: unknown route, a handler raising HTTPForbidden, and a raised redirect.

The error middleware rendered error.html for every HTTPException but
returned it with status 200, so a 404 or 403 looked like a success to
health probes, monitoring and Sentry. Pass the exception's status to
the renderer, and let redirects raised as exceptions pass through.
@Mariatta
Mariatta merged commit 74d44d6 into main Oct 20, 2026
17 checks passed
@Mariatta
Mariatta deleted the error-status-codes branch October 20, 2026 20:38
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.

1 participant