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

Docs for handing error pages are not ideal #6420

Open
ctolkien opened this issue Sep 16, 2024 · 3 comments
Open

Docs for handing error pages are not ideal #6420

ctolkien opened this issue Sep 16, 2024 · 3 comments

Comments

@ctolkien
Copy link
Contributor

What type of issue is it? (Choose one - delete the others)

Wrong documentation

What article/section is this about?

(link here)

Describe the issue

This section describes intercepting the 500 error response and then redirecting the user to a page to display the error. In this scenario statuscode is lost, and the user never actually receives a 500 error, they end up receiving a 3XX redirection.

This should probably be using some combination of app.UseExceptionHandler("..."); and app.UseStatusCodePagesWithReExecute("/error/{0}");

@sofietoft
Copy link
Contributor

Thanks for reporting this @ctolkien ! 💪 Much appreciated!

Now, this might be a stupid question, so please forgive me, but isn't it in most cases better for the user to not see the error, than for them to see it? 😅

In any case, would you be up for suggestion a rewrite of this guide, to include your suggestions?
Sounds like you already have some experience with this, and might know how it could be set up differently.

@ctolkien
Copy link
Contributor Author

Now, this might be a stupid question, so please forgive me, but isn't it in most cases better for the user to not see the error, than for them to see it?

Yep, to be clear, the issue is not the content that is shown. It is that the current flow is:

  • UnhandledExceptionIsRaised -> Global Exception Handler fires -> Re-executes the /error controller -> User is sent a 302 redirect to the error page (/statuscode/500) -> user browser redirects to the end page, is shown the "error" page, but with a 200 ("OK") status code.

When a user hits an error, ideally the URL does not change, they should get the error on the same URL they are on, showing the error content, but at the current URL with a 500 status code.

In any case, would you be up for suggestion a rewrite of this guide, to include your suggestions?
Sounds like you already have some experience with this, and might know how it could be set up differently.

Yes, let me do a bit more digging on handling the use cases. There are some further considerations, for instance you ideally want to have the 500 page be static content and not be rendered via the CMS. If there is an issue in your Layout file (for instance), which means that no page can work - including the 500 page, then your user will not see the properly rendered 500 page. By having it be as simple as possible, with no dependencies, that would be the most reliable option.

@sofietoft
Copy link
Contributor

Aha, yes, I see what you mean 🤔
By using the redirect method the context is lost and what they're seeing is actually "okay".

It would be great if you could suggest a better method here!
I like the idea with using a static page - that should always be available to show, at least in some form!

Hacktoberfest starts next month, and this sounds like a perfect little side task for that 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants