defaultRetryEvaluator method
Returns true only if the response hasn't been cancelled or got a bas status code.
Implementation
// ignore: avoid-unused-parameters
FutureOr<bool> defaultRetryEvaluator(
DioException error,
int attempt,
) async {
bool shouldRetry;
if (error.type == DioExceptionType.badResponse) {
final statusCode = error.response?.statusCode;
shouldRetry = statusCode != null && needRetry(statusCode);
} else if (error.type == DioExceptionType.unknown) {
try {
final result = await InternetAddress.lookup('baidu.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
shouldRetry = true;
} else {
shouldRetry = true;
}
} on SocketException catch (_) {
await toNoInternetPageNavigator?.call();
shouldRetry = true;
}
} else if (error.type == DioExceptionType.connectionError) {
await toNoInternetPageNavigator?.call();
shouldRetry = true;
} else {
shouldRetry = error.type != DioExceptionType.cancel;
}
return shouldRetry;
}