RetryInterceptor class
A Dio interceptor that automatically retries failed requests with exponential backoff.
This interceptor handles transient failures by retrying requests that fail due to:
- Connection timeouts, send timeouts, receive timeouts
- Network errors (no internet connection)
- Configurable HTTP status codes (default: 408, 429, 500, 502, 503, 504)
The delay between retries increases exponentially to avoid overwhelming servers that may be experiencing high load.
Example:
dio.interceptors.add(
RetryInterceptor(
dio: dio,
retryOptions: RetryOptions(
enabled: true,
maxRetries: 3,
initialDelay: Duration(milliseconds: 500),
),
),
);
- Inheritance
-
- Object
- Interceptor
- RetryInterceptor
Constructors
- RetryInterceptor({required Dio dio, required RetryOptions retryOptions})
- Creates a new RetryInterceptor.
Properties
- dio → Dio
-
The Dio instance used to retry requests.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- retryOptions → RetryOptions
-
Configuration options for retry behavior.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
DioException error, ErrorInterceptorHandler handler) → void -
Handles errors and retries the request if appropriate.
override
-
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → void -
Called when the request is about to be sent.
inherited
-
onResponse(
Response response, ResponseInterceptorHandler handler) → void -
Called when the response is about to be resolved.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited