Handle infinite loading
states when a restart occurs in the middle of a request.
#612
Labels
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
When using any kind of persisted storage, the app may restart while a request is in
loading
waiting for it to finish. In this case, the request will arrive here:axios-cache-interceptor/src/interceptors/request.ts
Lines 168 to 178 in b731b2c
Which is when we have a loading state but no deferred is registered (as it is a in memory promise hash map). Previously we just deleted the cache and continued with a
empty
response to be handled by the response interceptor.If the response of this request comes successful, it would ignore caching and return here:
axios-cache-interceptor/src/interceptors/response.ts
Lines 99 to 107 in b731b2c
Or, if this response failed, it would re-throw the error thinking the interceptor broke:
axios-cache-interceptor/src/interceptors/response.ts
Lines 270 to 280 in b731b2c
The responses interceptors are right to expect a
loading
state, otherwise non loading requests should've been resolved from the request interceptor already.To solve this problem, the check below must be done in the
ignoreAndRequest
code block to fix the cache to loading before returning the response.axios-cache-interceptor/src/interceptors/request.ts
Lines 164 to 165 in b731b2c
The text was updated successfully, but these errors were encountered: