shouldRetry method
判断是否应该重试
Implementation
bool shouldRetry(DioException error, int attemptNumber) {
if (attemptNumber >= maxAttempts) return false;
// 检查网络相关错误(连接、超时等)
final isNetworkError =
error.type == DioExceptionType.connectionError ||
error.type == DioExceptionType.connectionTimeout ||
error.type == DioExceptionType.receiveTimeout ||
error.type == DioExceptionType.sendTimeout;
if (isNetworkError) return true;
// 如果配置为只重试网络错误,则不检查HTTP状态码
if (retryOnlyNetworkErrors) return false;
// 检查HTTP响应错误
if (error.type == DioExceptionType.badResponse) {
final statusCode = error.response?.statusCode;
if (statusCode != null && retryableStatusCodes.contains(statusCode)) {
return true;
}
}
return false;
}