Error Catching not working with suspense true #959
Replies: 15 comments
-
@AmmarMohamadIsmaeel As the document describes, you have to use an error boundary instead of the error property.
|
Beta Was this translation helpful? Give feedback.
-
Thank you for the reply @koba04 I want each component to handle its different errors, How could I do this? |
Beta Was this translation helpful? Give feedback.
-
@AmmarMohamadIsmaeel <ErrorBoundaryA>
<PageA />
</ErrorBoundaryA>
<ErrorBoundaryB>
<PageB />
</ErrorBoundaryB> or <ErrorBoundary errorType="a">
<PageA />
</ErrorBoundary>
<ErrorBoundary errorType="b">
<PageB />
</ErrorBoundary> Does it make sense? |
Beta Was this translation helpful? Give feedback.
-
Yes, Thank you but How Can I use such a thing inside a map for routes?
|
Beta Was this translation helpful? Give feedback.
-
Sorry, I'm not sure about your router implementation, but couldn't you wrap your page components by error boundaries? |
Beta Was this translation helpful? Give feedback.
-
Yes, It worked, Thank you so much for your help! |
Beta Was this translation helpful? Give feedback.
-
👍 BTW, |
Beta Was this translation helpful? Give feedback.
-
@AmmarMohamadIsmaeel Could you close this issue if you don't have any other questions? |
Beta Was this translation helpful? Give feedback.
-
In the end, I use the package react-error-boundary to handle the error:
and place it between the routes.
But still, I am having a problem, is that the SWR is caching the error, so the error boundary is still handling the error even when its resolved, Can I use isValidating in the error handler function to only redirect if isValidating is false ? |
Beta Was this translation helpful? Give feedback.
-
Could you create a CodeSandbox project to reproduce it? |
Beta Was this translation helpful? Give feedback.
-
@koba04 Here is something like my code. https://codesandbox.io/s/zealous-williams-38jhe?file=/src/App.js My problem is: If the rest api resturns me and error for some reason maybe 403, and then I fix the problem in the api, and try again without refreshing the page, The response will also be 403 error since its cached and I am returning back to the error page |
Beta Was this translation helpful? Give feedback.
-
@AmmarMohamadIsmaeel How about the solution? |
Beta Was this translation helpful? Give feedback.
-
@koba04 Unfortunately It did not work, I am now in an infinite loop of calling the request and the error boundary is not handling the error. |
Beta Was this translation helpful? Give feedback.
-
@AmmarMohamadIsmaeel Thanks. How can I reproduce your case? |
Beta Was this translation helpful? Give feedback.
-
1- Make an api call using axios and swr with suspense true in a compoenent...Something like this:
2- Implement Error Boundary with fallback between the routes...Something like this:
3- Add The swr global config in the App.js to clear the cache on error...Something like this:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
useSWR catching errors is not working when adding to the options suspense true
The code will never enter the if the statement of the error and the website will carshes
and If we remove the suspense true everything will work fine
Beta Was this translation helpful? Give feedback.
All reactions