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

catch Response in middleware #9880

Closed

Conversation

arty-name
Copy link
Contributor

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 of Error in the middleware.

Related issues & labels (optional)

  • Suggested label: add new content

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 299f3af
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/6721f3477d2ab500082c7566
😎 Deploy Preview https://deploy-preview-9880--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@astrobot-houston
Copy link
Contributor

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

Locale File Note
en guides/server-side-rendering.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@arty-name
Copy link
Contributor Author

@sarah11918
Copy link
Member

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.

@sarah11918 sarah11918 closed this Oct 30, 2024
@arty-name
Copy link
Contributor Author

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"…

@sarah11918
Copy link
Member

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.

@arty-name
Copy link
Contributor Author

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.

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.

3 participants