shouldRetryRequest function

FutureOr<bool> shouldRetryRequest(
  1. DioException error,
  2. int attempt
)

Decides whether a failed request should be retried. Used as RetryInterceptor's retryEvaluator callback.

Certificate pinning failures, timeouts, unauthorized responses, and connection/cancellation errors are never retried; everything else defers to DefaultRetryEvaluator.

Implementation

FutureOr<bool> shouldRetryRequest(DioException error, int attempt) {
  final Object? mapped = error.error;

  if (mapped is CertificatePinningException) return false;
  if (mapped is TimeoutException) return false;
  if (mapped is UnauthorizedException) return false;
  if (error.type == DioExceptionType.connectionError) return false;
  if (error.type == DioExceptionType.cancel) return false;

  return DefaultRetryEvaluator(defaultRetryableStatuses).evaluate(error, attempt);
}