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

[✨] Centralized custom error pages #2285

Closed
Nefcanto opened this issue Nov 26, 2022 · 10 comments
Closed

[✨] Centralized custom error pages #2285

Nefcanto opened this issue Nov 26, 2022 · 10 comments
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: enhancement New feature or request

Comments

@Nefcanto
Copy link

Is your feature request related to a problem?

A typical website might have these modules:

  • Blog
  • Shop
  • Dynamic pages
  • Gallery
  • etc.

The way docs says, for now, we need to check for response status code on each page, and if it's 404, return a 404 response, and if it's 500, return a 500 response, etc.

This is hugely cumbersome and extremely inefficient.

Almost all web frameworks have a centralized way to return 404 or 500 or other custom pages related to the status code of the HTTP response.

For example, Next.js or ASP.NET Core let you create a page called 404.js or 404.cshtml and centralize your UI there.

Describe the solution you'd like

Right now, I'm thinking of higher-order components to centralize my response logic for 404 and 500, and 410 responses.

However, this means that everywhere I should use withNotFound(withError(withGone(MyComponent))) which is extremely inefficient, ugly, and hard to maintain.

Describe alternatives you've considered

If in onGet or onPost or other onX methods we returned any code other than 200, then let us create a page by that status code and serve that page instead.

Additional context

No response

@Nefcanto Nefcanto added TYPE: enhancement New feature or request STATUS-1: needs triage New issue which needs to be triaged labels Nov 26, 2022
@nnelgxorz
Copy link
Contributor

Related #2175

@Nefcanto
Copy link
Author

@nnelgxorz yep, it seems that #2175 is what we expect to have.

@nnelgxorz
Copy link
Contributor

Looks like that PR should already be in the latest release. I haven't tried it myself yet.

@zanettin
Copy link
Collaborator

Hi @Nefcanto
Just wanted to check if the issue could be resolved with the latest qwik-city beta and the mentioned PR by @nnelgxorz ?

@Nefcanto
Copy link
Author

@zanettin, will test it and reply back. Thank you for following up.

@zanettin
Copy link
Collaborator

zanettin commented Feb 6, 2023

Hi @Nefcanto 👋
Sry to ping you again 👼 any updates regarding that one?

@Nefcanto
Copy link
Author

Nefcanto commented Feb 7, 2023

@zanettin you're such a gentleman to follow up. I'm sorry for forgetting this. Today I tested it and it did not work. I created a page called 404.jsx at the top src/routes/404.jsx directory and then I went into a non-existing route/page. For example example.local/non-existing-route and it showed the default 404 page. I also renamed the 404.jsx to 404.tsx but that had no effect.

I'm using Qwik version 0.17.4 which is the latest version at the time of writing this.

Again, sorry that I forgot.

@zanettin
Copy link
Collaborator

zanettin commented Feb 7, 2023

Thanks a lot for your test @Nefcanto and the kind words 🙏 and sorry for the inconvenience and misleading answer from my side. i've checked it on my end with the same result. maybe @adamdbradley can give us a hand/hint on how it should work?

@RaeesBhatti
Copy link
Contributor

I'm curious why this is logged in the Post V1 backlog. This seems like a very important functionality and something that should be decided upon before V1.
Also, I think this should be tagged as a bug rather than an enhancement since the documentation mentions that a custom 404-page template is possible but it's actually not.

@gioboa
Copy link
Member

gioboa commented Aug 26, 2023

I close this issue because the function is in the framework. There is a specific issue for 404 problem #5030 and I think we should open new issues and not continue in this old thread.

@gioboa gioboa closed this as completed Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants