RetryInterceptor class

Middleware that retries failed requests with exponential backoff.

By default retries on 429 (rate limited) and 5xx (server errors), as well as network-level exceptions.

final config = ApiConfig(
  client: myClient,
  interceptors: [
    RetryInterceptor(maxRetries: 3),
  ],
);
Implemented types

Constructors

RetryInterceptor({int maxRetries = 3, Duration initialDelay = const Duration(milliseconds: 500), bool retryWhen(StreamedApiResponse response)?, bool shouldRetryRequest(ApiRequest request)?, double jitterRatio = 0.25, RetrySleep? sleep, RetryRandom? random, Duration? maxDelay})
Creates a RetryInterceptor with configurable retry behavior.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
initialDelay → Duration
Delay before the first retry. Subsequent retries multiply by 2.
final
jitterRatio → double
Random jitter ratio applied to exponential backoff.
final
maxDelay → Duration?
Maximum delay between retries, capping exponential growth.
final
maxRetries → int
Maximum number of retries (not counting the initial attempt).
final
random → RetryRandom?
Custom random function for testing. Defaults to Random.nextDouble.
final
retryWhen → bool Function(StreamedApiResponse response)?
Custom predicate to decide whether a response should be retried. If null, retries on 429 and 5xx.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
shouldRetryRequest → bool Function(ApiRequest request)?
Custom predicate to decide whether a request is safe to retry. If null, retries only idempotent methods by default.
final
sleep → RetrySleep?
Custom sleep function for testing. Defaults to Future.delayed.
final

Methods

intercept(ApiRequest request, Handler next) → Future<StreamedApiResponse>
Processes request and optionally delegates to next.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited