DioRetryRules class final
Decides which Dio errors are worth retrying, and how long to wait.
Pass shouldRetry as retryIf and retryDelay as retryDelay when
registering a handler that uses Dio:
const rules = DioRetryRules();
queue.register<UploadTask>(
type: 'upload',
decoder: UploadTask.fromJson,
handler: upload,
retryIf: rules.shouldRetry,
retryDelay: rules.retryDelay,
);
The task's RetryPolicy still limits the number of attempts.
Constructors
-
DioRetryRules({Set<
int> retryStatusCodes = defaultRetryStatusCodes, bool retryTimeouts = true, bool retryConnectionErrors = true, bool useRetryAfter = true, Duration maxRetryAfter = const Duration(hours: 1), DateTime now()?}) -
Creates rules. The defaults retry timeouts, connection failures, and the
status codes in defaultRetryStatusCodes, and honor
Retry-Afterup to one hour.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxRetryAfter → Duration
-
Longest
Retry-Afterdelay that is honored; longer values are capped.final - now → DateTime Function()?
-
Clock for HTTP-date
Retry-Aftervalues. Defaults to DateTime.now.final - retryConnectionErrors → bool
-
Whether connection failures (DNS, refused, reset, offline) are retried.
final
-
retryStatusCodes
→ Set<
int> -
HTTP status codes that are retried. Every other status fails the task.
final
- retryTimeouts → bool
-
Whether connect, send, and receive timeouts are retried, and attempts
that ran past the
timeoutgiven toDurableQueue.register(TaskTimeoutException).final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- useRetryAfter → bool
-
Whether a
Retry-Afterresponse header sets the next delay.final
Methods
-
deferOn(
String gate) → DeferOnError -
A
register(deferOn:)rule that sends connection errors togate. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
retryDelay(
Object error, StackTrace stackTrace) → Duration? -
The delay a response asked for with
Retry-After, or null to use the task's retry policy. -
shouldRetry(
Object error, StackTrace stackTrace) → bool -
Whether
errorshould be retried. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
isConnectionError(
Object error) → bool -
Whether
errormeans the server could not be reached at all: aDioExceptionof typeconnectionError(DNS failure, refused, reset, offline) orconnectionTimeout.
Constants
-
defaultRetryStatusCodes
→ const Set<
int> - 408 Request Timeout, 425 Too Early, 429 Too Many Requests, 500, 502, 503, and 504.