T
TanStack11mo ago
correct-apricot

Best way to catch/handle errors during streaming

Hello, I am getting the error A query that was dehydrated as pending ended up rejecting. but I am unable to try/catch it and unsure of the best way to handle these errors. snippet/example of what I am doing:
...
queryClient.prefetchQuery(myQuery);

return (
<HydrationBoundary state={dehydrate(queryClient)}>
{children}
</HydrationBoundary>
);
...
queryClient.prefetchQuery(myQuery);

return (
<HydrationBoundary state={dehydrate(queryClient)}>
{children}
</HydrationBoundary>
);
However, in this case it is throwing from a 404. I want to catch this and redirect. Given I am in a server component, I tried to try/catch with a redirect to no avail. It is just showing my error boundary. What is the best way to handle this error? Or perhaps more specifically, how can I catch this error and redirect/do some other action? Thanks!
4 Replies
conscious-sapphire
conscious-sapphire11mo ago
prefetchQuery doesn't throw. If you want try/catch, use fetchQuery instead
correct-apricot
correct-apricotOP11mo ago
Hey thanks for the response! With fetchQuery I still get A query that was dehydrated as pending ended up rejecting. and wrapping it with try/catch doesn't catch the error. It does if I await, but I want the result to stream. Thanks!
conscious-sapphire
conscious-sapphire11mo ago
If you want to stream it, you can't catch it on the server...
correct-apricot
correct-apricotOP11mo ago
Gotcha! I wasn't sure given the errors show up on my server console. The error boundary showing is good enough for me. Thanks!

Did you find this page helpful?