Issues with Caching and Error Handling in Svelte Query #8238
Unanswered
kimonneuhoff
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
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
throw error(400, "Not implemented");
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 issue:
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!
Beta Was this translation helpful? Give feedback.
All reactions