Repository navigation
Retries
Transient failures can be retried automatically with exponential backoff. Off by default.
final client = WordpressClient.forSite(
siteUrl: Uri.parse('https://example.com'),
bootstrapper: (b) => b.withRetryPolicy(const RetryPolicy.standard()).build(),
);RetryPolicy.standard(): up to 3 tries (1 initial + 2 retries), 500 ms base delay doubling each time, jittered, Retry-After honoured.
A request is retried when all of these hold:
- The method is in
methods:GET,HEAD,OPTIONS,PUT,DELETEby default.POSTandPATCHare never retried unless you add them, so a create cannot be sent twice by accident. - The failure is transient: a timeout or connection error (
retryOnNetworkError), or a status instatusCodes(429,502,503,504). - The body is replayable. Multipart uploads and streamed bodies are not retried.
- Fewer than
maxAttemptstries have been made.
Cancelled requests are never retried, and cancelling during the wait stops it immediately.
const RetryPolicy(
maxAttempts: 4, // total tries, including the first
baseDelay: Duration(seconds: 1), // delay before retry 1; doubles each time
maxDelay: Duration(seconds: 20), // cap for the computed delay
jitter: true, // wait 50-100% of the computed delay
statusCodes: {429, 503},
methods: {HttpMethod.get, HttpMethod.head},
retryOnNetworkError: true,
honorRetryAfter: true, // use the Retry-After header when present
maxRetryAfter: Duration(seconds: 30), // longer Retry-After: give up and return the response
)With Retry-After present the server's delay is used as is; otherwise the delay is baseDelay * 2^(retry-1), capped by maxDelay.
Only WordpressRequest (raw requests, custom interfaces) carries a policy; it overrides the client's.
await client.raw(WordpressRequest(
method: HttpMethod.get,
url: RequestUrl.relative('posts'),
retryPolicy: RetryPolicy.none, // never retry this one
));final raw = await client.raw(request);
print(raw.extra[WordpressRequest.metaAttempts]); // 1 when it worked first timeduration on the response covers all tries and waits.
-
Auth: a
401on arequireAuthrequest triggers one re-authentication and a retried request, independent of the policy. - Cache: only the network call is retried; a cache hit never reaches the retry loop.
-
GraphQL: queries sent with
useGet: trueare retried (GET); regularPOSTqueries are not. See GraphQL. -
Tests: set
sleep: (_) async {}to skip waiting. See Testing.
If you also add a retry interceptor with withDioInterceptor, retries multiply. Use one mechanism.
Getting started
- Usage
- Bootstrap and Configuration
- Authorization
- Browser Sign-In
- WordPress.com and Jetpack
- Multisite
- Supported REST Methods
Requests and data
- Sending Requests
- Error Handling and Responses
- Fluent Queries
- Interfaces and Extensions
- Custom Post Types
- Model Generator
- Meta and ACF
- Concurrent Edits
- Batch Requests
- Embed and Fields
- Pagination and Finders
- Parallel Requests
- Streaming and Polling
- Pattern Directory Items
Behaviour
- Retries
- Caching
- Request De-duplication and Concurrency
- Middlewares
- Logging
- Offline Write Queue
- Events and Statistics
Other APIs
Extend and test
Reference