dio_smart_retry
Dio और Dio पैकेज के लिए रीट्राई लाइब्रेरी, प्यार से बनाई गई। डिफ़ॉल्ट रूप से, केवल उचित रीट्राई योग्य HTTP स्थितियों के लिए ही अनुरोध को दोहराया जाएगा।
Dio के लिए लचीला पुनर्प्रयास पुस्तकालय। एक छोड़ दिए गए dio_retry पैकेज की अगली पीढ़ी।
^5.7.0^4.0.2^1.9.0^5.7.6^1.25.8^6.0.0यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
Pub Version Dart SDK Version style: very good analysis License
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.
dio_smart_retry: ^7.0.0 **import 'package:dio_smart_retry/dio_smart_retry.dart'** For the old dio (ver. 4.+) use dio_smart_retry: ^1.4.0
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 retry
Duration(seconds: 2), // wait 2 sec before second retry
Duration(seconds: 3), // wait 3 sec before third retry
],
));
/// Sending a failing request for 3 times with 1s, then 2s, then 3s interval
await dio.get('https://mock.codes/500');
See example/dio_smart_retry_example.dart.
Responses with these http status codes will be retried by default:
It's possible to manually disable retry for a specified request. Use disableRetry extension for that:
final request = RequestOptions(path: '/')
..disableRetry = true;
await dio.fetch<String>(request);
or
final options = Options()
..disableRetry = true;
await dio.get<String>('/', options: options);
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 },
)
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');
Use MultipartFile instead of MultipartFileRecreatable.