Repository navigation
|
So we can define a data function to be used in a route like the example in the README: This works well when the API call works as expected, but how should we handle API errors? with the example code above we just end with an error in the console and a broken app... anybody knows? |
Answered by
ryansolid
Sep 21, 2022
Replies: 1 comment 1 reply
|
There are 2 ways to look at this. You can handle the error automatically like retry logic in the fetcher of your resource. Resource takes a promise so doesn't matter what it is. The other probably more common option is to handle it where it is read. Wrap with Error Boundary, or use the error property on the resource. You may also want to pass down the refetch option from the resource constructor if you want it to refetch. |
1 reply
Answer selected by
manast
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are 2 ways to look at this. You can handle the error automatically like retry logic in the fetcher of your resource. Resource takes a promise so doesn't matter what it is.
The other probably more common option is to handle it where it is read. Wrap with Error Boundary, or use the error property on the resource. You may also want to pass down the refetch option from the resource constructor if you want it to refetch.