SmartRetryInterceptor class

支持动态 RetryEvaluator 的重试拦截器

基于 dio_smart_retry 的 RetryInterceptor,增加从 RequestOptions.extra 读取动态 evaluator 的能力,以支持单次请求级别的重试策略覆盖。

工作原理

  1. 安装时可传入默认的 retryEvaluator
  2. 每次请求时,检查 options.extra[kRetryEvaluatorKey] 是否存在动态 evaluator
  3. 如果存在,使用动态 evaluator;否则使用默认 evaluator

使用方式

通常不直接使用此类,而是通过 RetryPlugin 间接使用:

// RetryPlugin 会在 onRequest 时设置动态 evaluator
SmartDio.get('/api',
  extraPlugins: [
    RetryPlugin(shouldRetry: (e) => e is NetworkError),
  ],
);
Inheritance

Constructors

SmartRetryInterceptor({required Dio dio, void logPrint(String message)?, int retries = 3, List<Duration> retryDelays = const [Duration(seconds: 1), Duration(seconds: 2), Duration(seconds: 3)], RetryEvaluator? retryEvaluator, bool ignoreRetryEvaluatorExceptions = false, Set<int> retryableExtraStatuses = const {}})

Properties

dio Dio
The original dio
finalinherited
hashCode int
The hash code for this object.
no setterinherited
ignoreRetryEvaluatorExceptions bool
Ignore exception if _retryEvaluator throws it (not recommend)
finalinherited
logPrint → void Function(String message)?
For logging purpose
finalinherited
retries int
The number of retry in case of an error
finalinherited
retryableExtraStatuses Set<int>
Specifies an extra retryable statuses, which will be taken into account with defaultRetryableStatuses IMPORTANT: THIS SETTING WORKS ONLY IF _retryEvaluator is null
finalinherited
retryDelays List<Duration>
The delays between attempts. Empty retryDelays means no delay.
finalinherited
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 err, ErrorInterceptorHandler handler) Future<void>
Called when an exception was occurred during the request.
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