Issues with Caching and Error Handling in TanStack Svelte Query
Hi,
I've recently discovered this library and have spent a few hours trying to implement it, but I'm running into some issues regarding caching and error handling.
My Implementation
2 Replies
equal-aquaOP•11mo ago
Issues
Caching Behavior: I don’t understand how to get the caching to work properly. With the default configuration, it seems like the cached data is never used. I expected the cached data to be utilized when, for example, I change the fetch URL to an API that doesn’t exist. However, when the fetch fails, even with an error response, the cached data is not used.
After calling an API that doesn’t exist, the logs are as follows:
Shouldn't the cached data be returned in this case? Additionally, when I trigger an error in the API using the logs are as follows:
Here, even though I returned a status code of 400, as in the previous case, it is still trying to cache the response and won't return the cached data, but it will also say that the query was successful and didn't fail - which seems incorrect and leads to my second question:
Handling Query Failures: How can I ensure that a query fails appropriately? When I throw an error in my API or return an error status code, the library still indicates that everything is fine. It’s confusing because I would expect it to retry or use the cache when the API fails, but it doesn't seem to behave this way.
I would appreciate any guidance on how to resolve these issues. Thank you for your help!
equal-aquaOP•10mo ago
i created a github ticket for this https://github.com/TanStack/query/discussions/8238
GitHub
Issues with Caching and Error Handling in Svelte Query · TanStack q...
Hi, I've recently discovered this library and have spent a few hours trying to implement it, but I'm running into some issues regarding caching and error handling. My Implementation const q...