-
Notifications
You must be signed in to change notification settings - Fork 108
Get stale cache on network error #20
Comments
I've put something together, let me know what you think: https://gist.github.com/FMCorz/540bdd3e740d69dbf84fa0dc17cea940 |
Hi @FMCorz ! Awesome idea 👍 There's several things to consider when developing such a fallback. First you're right there is no try/catch around the default adapter call because I wanted to leave that burden in the user land. Your implementation looks fine! 😃 We should also consider if this action should trigger on any kind of network error (4xx, 5xx). I guess we could have an option
Any of these would automatically set the I'm probably overthinking it. Maybe we can implement the simple version first and see from there. The first cache read (before using the default adapter) should still throw a Do you want to have a go at this? Else I'll give it a try soon. Cheers 🍻 |
Ok this got me intrigued so I setup a branch trying to add this feature check out the linked PR 😃 |
Heh, I didn't have time to give it a go ;-). I agree with your comments. You will see in the comments I left on the PR what I think about handling the statuses, etc... It might be better to have functions that do these things, rather than trying to cater for all needs at once. Example:
Now, in these examples you cannot substitute the response, you can only dynamically tell whether the stale cache should be used. But another issue could be adding What do you think? |
Hi,
I would like to be able to return the cache when Axios returns a network error. From what I can see it is not possible as it is because the cache store throws an error when the cache is stale. And also because there is no wrapper try/catch around the call to the default adapter. Is that right?
Would you be interested in supporting such feature? If yes, how would you recommend it to be coded?
Thanks!
Fred
The text was updated successfully, but these errors were encountered: