-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
catch Response in middleware #9880
Conversation
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
Hi @arty-name, thanks for wanting to improve our documentation! Unfortunately, this isn't the kind of content we typically document. As I'm sure you can understand, we have to stick with documenting how core Astro features work or else we could end up documenting every practice/example under the sun. 😅 So, showing practices for reducing duplicate or boilerplate JavaScript code aren't really the mandate of Astro docs. Tips like this can make great blog posts for self-publishing, or we'll often suggest working with https://astro-tips.dev/ to see if your content is a fit there! Unfortunately, it's not something for our official documentation so I'm closing this PR. But, we hope you'll find a place to share it with others. |
Thank you for looking into this, @sarah11918! Fair enough, the documentation cannot include everything. Would you also object to including a single sentence in the existing section? Something along the lines "You can also throw this Response and catch it in the middleware"… |
Hi, I have been discussing with the team and they feel like the middleware page itself covers this adequately. However we have been talking about what improvements on this page, maybe better linking to the middleware page we might want to make so that it's clearer what people can do with middleware and in which rendering situations (prerendering vs on demand). But, the goal of this page is simply to point out what becomes available with on demand rendering, which includes some middleware features, not to fully document using middleware itself. |
Thank you for your patience, @sarah11918! I admit I don’t have a good overview of the documentation, but what you and the team say about middleware doesn’t seem really true to me as a consumer of the docs. I’d like to highlight to you this difference in perception. The middleware page doesn’t mention catching of exceptions at all, and the option to create a new Response is hidden in an example of transformation, easy to gloss over. The SSR page was the only one I found which showcases the returning of manually created Responses. I don’t push for changes anymore and accept your decision. |
Description (required)
This PR describes a design pattern to reduce boilerplate code in pages. When some error condition in a function should always be handled by returning a specific
Response
, repeating this code in all the pages is cumbersome. You can instead catch a special subclass ofError
in the middleware.Related issues & labels (optional)