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:
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•11mo ago
prefetchQuery doesn't throw. If you want try/catch, use
fetchQuery
insteadcorrect-apricotOP•11mo 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•11mo ago
If you want to stream it, you can't catch it on the server...
correct-apricotOP•11mo 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!