Is there some cases where createResource doesn't handle errors ?
Hello,
I have this particular case where I'm fetching data based on searchParams and I have a basic error from the back-end:
My fetcher return a rejected promise, but it seems that it's not handled by createResource. I tryed to reproduce my case on a simpler example but I didn't succeed.
I patched my issue using a catch manually in the createResource fetcher, but well ... I can't use native error handling mechanism (and ofc I could also have use ErrorBoundary but it didn't suit my needs)
Anyway, all this context that brings me to my main question : what are the cases that make createResource not handling error
2 Replies
A 404 response is not an error unless you throw it yourself. Otherwise, errors in resources are a bit difficult to understand.
If you check resource.error, you'll get any error or rejection thrown by the fetcher, but unless you evaluate resource(), it won't be propagated to the next boundary.
Yeah, the api.get handles 404 as error
Ok, I see, so the best way to make sure everything's fine should be to check if there's an error before evalutating resource() (and in case of error, don't evaluate resource()) !
Checking ... And ... yes, works as expected ! Always love you answers @lexlohr