Replies: 4 comments 3 replies
-
You could handle this in the layout page. The layout gets rendered along with the error page. Or even just within hooks itself you can do the check for instance if the route is /protected and the user is not authenticated, and then throw a redirect to the login page instead of throwing a 401 error. |
Beta Was this translation helpful? Give feedback.
-
What is wrong with redirecting to the login page? If the error.html will be a component, what should the server respond if error occur during the component rendering? It already tries to render the fallback error page. This is why the error.html must be as simple as possible. |
Beta Was this translation helpful? Give feedback.
-
I agree with OP & @wkille . We need a better solution. Also I feel I have to do quite a bit of gymnastics to style the error.html. I chose skeleton.dev with tailwindcss. It looks like many of the directives like, %sveltekit.assets%/ doesnt work. I am going to create a new discussion and reference this. |
Beta Was this translation helpful? Give feedback.
-
I would like to have this option as well. It would be easier if I was building my fallback page as .svelte file instead of barebone .html. I use this workaround at the moment to redirect my own error page and show the page content's based on the query details.
|
Beta Was this translation helpful? Give feedback.
-
In order to do some advanced navigation and auth guards I find myself having to put more and more logic into
hooks.server.ts
. And since errors in this part of the request lifecycle are rendered using the fallback error page, it's not possible to customize that error page very easily.Use case: auth guard where going to a protected route while not logged in should always render the login page/component at that URL.
/protected
hooks.server.ts#handle()
notices the route is protected and runsthrow error(401)
/protected
url)[401, 402].includes(statusCode)
and renderes theLogin
componentThe reason I'd like to have the fallback error page be a Svelte component (rather than the current "dumb" template) is because I'd like to customize the error page based on status code. As well as bring in any compiled CSS or other assets.
An alternative solution would be to enable different static fallback error pages based on status code like some other frameworks allow. e.g. 401.html, 404.html, etc.
Beta Was this translation helpful? Give feedback.
All reactions