shouldRetry method

bool shouldRetry({
  1. required int attempt,
  2. int? statusCode,
  3. required bool isNetworkError,
})

attempt is 1-based (1 = the first try that just failed).

Implementation

bool shouldRetry({required int attempt, int? statusCode, required bool isNetworkError}) {
  if (attempt > maxRetries) return false;
  if (isNetworkError) return true;
  if (statusCode == null) return false;
  return statusCode == 429 || (statusCode >= 500 && statusCode <= 599);
}