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

Error handling with PreloadQuery #393

Closed
MiroYar opened this issue Nov 25, 2024 · 6 comments
Closed

Error handling with PreloadQuery #393

MiroYar opened this issue Nov 25, 2024 · 6 comments

Comments

@MiroYar
Copy link

MiroYar commented Nov 25, 2024

Hello. Tell me how to correctly handle query error a type of GraphQLFormattedError. I preload user data using PreloadQuery, the correctness of the request depends on cookies, but if for some reason the cookies turn out to be incorrect, the error 401 Forbidden is returned. When I received this error, I wanted to redirect to the authorization page. I've tried several ways:

  1. I did not find any corresponding props in the PreloadQuery component, except for the errorPolicy="all" parameter, but then useSuspenseQuery tries to make a repeat request, which I would like to avoid;
  2. If redirect is used in the onError function in the client settings, then Next itself returns the error Error: NEXT_REDIRECT.
@phryneas
Copy link
Member

phryneas commented Nov 26, 2024

As that query finishes after your page has already partially rendered, it's probably not possible to do this on the server during RSC or SSR.

Your only chance is to do this in the browser, and if a server query failed, the browser will always try to restart it there - the error itself is currently not transported over (that will change for GraphQLFormattedError once we finish #389), so the browser has to restart.

@MiroYar
Copy link
Author

MiroYar commented Nov 27, 2024

Thanks for the reply. I understood you. The only thing I would like to know is how you estimate how long you will do the work #389, so that I will set a reminder to return to this problem.

@phryneas
Copy link
Member

It's very high on my list of priorities, but even more important things keep popping up.
Any other time of the year I'd say "a month", but with Thanksgiving and Christmas it could also take two.

@MiroYar
Copy link
Author

MiroYar commented Nov 27, 2024

Thank you very much.

@MiroYar
Copy link
Author

MiroYar commented Nov 27, 2024

I will close the issue while waiting for the implementation of the necessary feature

@MiroYar MiroYar closed this as completed Nov 27, 2024
Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

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

No branches or pull requests

2 participants