-
Notifications
You must be signed in to change notification settings - Fork 0
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
RFC: Standardise ServerErrors #205
Comments
Here's a PR tracking this work: QwikDev/qwik#7185 Some remaining tasks:
This change would also remove the error log here. Since errors can be intercepted by middleware this should be left to the user. When errors arent intercepted, they're returned to the frontend by default. If this is difficult for new comers facing their first errors, we can add a logging plugin to the starter templates. @shairez please let me know if Ive missed anything. |
The PR now includes documentation and tests for error middleware |
Thanks a lot @DustinJSilk ! 🙏 |
A few questions for the community:
|
About the first point- @QwikDev/qwik-team WDYT? About the second point - maybe we could add a middleware just for the API requests ( |
@DustinJSilk we talked with @mhevery and he suggested looking at the WDYT? |
Oh, of course! Thats a great idea and should be simple to implement 😄 |
Seems like server$ sends I'll need to check what the routeLoaders and actions send, during SSR and CSR |
In my tests, it looks like both routeLoader$ and server$ have the same Accept headers which makes this difficult. During SSR: |
@DustinJSilk but can't we assume that route loaders and server$ would be called in the context of an html rendered app? meaning, only calls that explicitly send that they accept json as a response should be getting the json / text error, and all the rest will receive the HTML error page. Or else I'm missing something here |
Hmm, possibly. We would need to then update the client server$ fetch so that it adds the A server$ can be called inside a routeLoader$ or a task$ which would have the text/html header, but you might try something like this: routeLoader$(() => {
try {
await someServer$Fun()
} catch (err) {
}
}) Would the err in the catch be html or the original thrown error? I might need to test this otherwise |
@shairez ive updated the PR to test for text/html and incuded further e2e tests for error handling |
@shairez gentle nudge here, can we progress this to the next phase? |
thanks Dustin! |
Discussed in #200
Originally posted by DustinJSilk December 15, 2024
What is it about?
ServerErrors should not return a value on the client, they should be thrown, and the error types should be the same for routeLoaders
What's the motivation for this proposal?
Problems you are trying to solve:
ServerError
in aserver$
function allows us to change the status code and payload of the repsonse. On the client, the value of the error is returned, rather than having the client throw the error so that it can be caught. This brings about a few challenges:server$
functions.server$
function has to return a tuple to handle the error path. See the original PR for an example: feat(server$): config argument, optional GET, ServerError qwik#6290server$
function which previously might throw a standard error now also requires changes to how the function is called due to the change in it's signature with a tuple responserouteLoader$
throws an error using the syntaxthrow event.error(500, 'some data')
. This has 2 significant issues:routeLoader$
expects a different error instance to theserver$
.Goals you are trying to achieve:
server$
errors as if they are standard errors on the client.Any other context or information you want to share:
This would be a breaking change, but I dont think this API is widely used currently considering it doesn't work in a dev build due to this error: QwikDev/qwik#7165
This means we might be able to implement this change as a minor version bump, although it would technically be a breaking change.
Proposed Solution / Feature
What do you propose?
server$
androuteLoader$
error types to both use aServerError
class which isn't part of the event object.Code examples
Links / References
Original ServerError PR: QwikDev/qwik#6290
The text was updated successfully, but these errors were encountered: