Flexible retry library for Dio package. This is a next generation of an abandoned dio_retry package.
By default, the request will be retried only for appropriate retryable http statuses.
Also, it supports dynamic delay between retries. Null Safety.
** For the old dio (ver. 4.+) use dio_smart_retry: ^1.4.0
Usage
Just add an interceptor to your dio:
final dio = Dio();
// Add the interceptor
dio.interceptors.add(RetryInterceptor(
dio: dio,
logPrint: print, // specify log function (optional)
retries: 3, // retry count (optional)
retryDelays: const [ // set delays between retries (optional)Duration(seconds: 1), // wait 1 sec before first retryDuration(seconds: 2), // wait 2 sec before second retryDuration(seconds: 3), // wait 3 sec before third retry
],
));
/// Sending a failing request for 3 times with 1s, then 2s, then 3s intervalawait dio.get('https://mock.codes/500');
It's possible to add you own retryable status codes. Use retryableExtraStatuses parameter for that. Here is an example:
RetryInterceptor(
dio: dio,
retryableExtraStatuses: { status401Unauthorized },
)
or:
RetryInterceptor(
dio: dio,
retryableExtraStatuses: { 401 },
)
Override retryable statuses
It's possible to override default retryable status codes list. Just make new instance of DefaultRetryEvaluator and pass your status codes there.
Here is an example:
final myStatuses = { status400BadRequest, status409Conflict };
dio.interceptors.add(
RetryInterceptor(
dio: dio,
logPrint: print,
retryEvaluator: DefaultRetryEvaluator(myStatuses).evaluate,
),
);
await dio.get<dynamic>('https://mock.codes/400');
Migrating to 7.0
Use MultipartFile instead of MultipartFileRecreatable.