Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expertimental rewrite: when target page throws an error, this results in "404 Not Found" #11110

Closed
1 task
arty-name opened this issue May 21, 2024 · 6 comments · Fixed by #11136
Closed
1 task
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope)

Comments

@arty-name
Copy link
Contributor

arty-name commented May 21, 2024

Astro Info

Astro                    v4.8.4
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 tried using rewrites for an existing page and they work fine! However sometimes this existing page throws an error, and this case is not handled well.

Without rewrite, Astro developer tools show a nice UI for exceptions thrown in the standalone Node backend.

With rewrite, this doesn’t happen. First of all, any kind of error results in a 404 Not Found message. Second, this is not handled by Astro developer tools, so after followup changes I need to manually reload the page to see results.

What's the expected result?

Astro developer tools should handle the exception. The original exception should be shown, not "Not Found".

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-h5n839?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label May 21, 2024
@ematipico
Copy link
Member

ematipico commented May 21, 2024

I suppose you're interested at the error only in dev mode, correct?

@arty-name
Copy link
Contributor Author

For more context: nicer error handling was my goal of using the rewrite feature, actually. I want the home page to show different views for two types of users that I have. Previously I conditionally included two components, which had a downside: any error in the component would be handled only in the middle of the response. This doesn’t happen with rewrites, but the DX is suboptimal.

@arty-name
Copy link
Contributor Author

I suppose you're interested at the error only in dev mode, correct?

For the developer tools, yes, I only expect them in dev mode.

For the error type… 404 Not Found would be quite misleading in production, I believe. It would be nice to propagate the original status somehow, maybe even the whole response.

@ematipico
Copy link
Member

The 404 Not Found is thrown if Astro can't find a route that corresponds to the URL you passed; this means that there's nothing to render, so there's no Response to pass upstream.

@arty-name
Copy link
Contributor Author

Thank you for taking time to respond, however I fail to apply this to the situation I have described.

Astro has definitely found a route that corresponds to the response. Route has generated an error, however. There is an error to render, but instead a 404 is rendered by the rewrite internals. When I comment out the error generation in the route, the route non-error response is rendered.

@ematipico
Copy link
Member

ematipico commented May 21, 2024

Perfect, thank you. I will think about what's best away to handle this use case.

@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope) and removed needs triage Issue needs to be triaged labels May 23, 2024
@ematipico ematipico self-assigned this May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants