-
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? |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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.