-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Experimental rewrite: Response with status:500 does not trigger 500.astro in production #11208
Description
Astro Info
Astro v4.10.0
Node v20.13.1
System Linux (x64)
Package Manager unknown
Output server
Adapter @astrojs/node
Integrations @sentry/astro
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I conditionally rewrite a page to one of two other pages, and both branches work fine.
Sometimes these pages throw errors, and the handling of this condition has been improved in #11110 👍
In production mode I show a nice error page provided in 500.astro and this works. It works even when I return new Response(null, { status: 500 }).
However if rewriting took place during the processing of the request, 500.astro is not rendered and the plain Response#status=500 is rendered.
Background for returning Response#status=500 is this. I use JSON logs in production to collect them in Kibana and process them automatically: each log prints just one line which is a JSON object. By default Astro prints the multiple-line stack trace for uncaught exceptions, so I catch exceptions in middleware and log them. Then I return new Response(null, { status: 500 }) so that Astro renders 500.astro.
What's the expected result?
When there’s 500.astro page it should be rendered every time Astro receives Response#status=500, regardless of rewriting.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-h5n839-ifnpfx?file=src%2Fpages%2Findex.astro
Participation
- I am willing to submit a pull request for this issue.