redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

There is no way to identify if there was an error in first try for rtk query

Open heypran opened this issue 4 years ago • 1 comments

Background: RTK query provides built-in exponential retry ( default value 5). The doc mentions one parameter to control retries which is maxRetries which requires the query to be wrapped with retry utility. This works fine.

Issue: However, when the first request fails, the query status remains pending, isFetching is true and isError state is still set to false. In this case, there is no way to know whether query is retrying or fetching for the first time or in other words there is no way to if there was an error in first try.

heypran avatar Nov 29 '21 11:11 heypran

This one is a little tricky I think. You can see here that the retry logic built into rtk-query is meant to be blocking.

This is because the current retry logic is build as a query enhancer where as what you want is closer to the polling middleware.

I wonder if the best way to achieve what you want is to create an enhancer that implicitly sets two fields for queries:

  • refetchOnError to false
  • pollingInterval to the time until the retry should happen (dynamically updates every time the query fails)

Maybe this approach doesn't work for some reason though (probably somebody more familiar on rtk query needs to step in)

SebastienGllmt avatar Dec 05 '21 20:12 SebastienGllmt