Customized useErrorBoundary errors #2763
-
Hello, I discovered that we can force reactQuery to propagate the errors to the nearest errorBoundary, which is working fine in my application ! But the problem is, we can't propagate custom errors with custom messages, or can we ? I can't seem to find an appropriate solution. Can you help me ? Thanks in advance ! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
usually, your error would contain specifics about the error itself. For example, if you're using so, it really depends on how you're doing the actual data fetching. As far as react-query is concerned, whatever you
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your response ! But I thought error boundary can't catch error from queries ? So if I throw errors from queries it will not work, or am I wrong ? I, indeed, use axios to fetch my data. |
Beta Was this translation helpful? Give feedback.
-
That’s where |
Beta Was this translation helpful? Give feedback.
-
Okay, I understand, but my error boundary only receive a message, not a proper status so i can't really do nice error handling nor conditional rendering in my error boundary, there is no solution to send a custom error object to my error boundary ? |
Beta Was this translation helpful? Give feedback.
That’s where
useErrorBoundary
comes in. If you set it t to true, RQ will re-throw the error in the next render cycle so that the ErrorBoundary will catch it. See: https://tkdodo.eu/blog/react-query-error-handling