get method

Future<List<int>> get(
  1. String path
)

Make an HTTP GET request with failover support

Implementation

Future<List<int>> get(String path) async {
  int attemptCount = 0;
  Object? lastError;

  while (attemptCount < urls.length) {
    try {
      final url = _buildUrl(workingUrl, path);
      final response = await _httpClient
          .get(url)
          .timeout(const Duration(seconds: 10));

      if (response.statusCode >= 400) {
        _handleError(response);
      }

      return response.bodyBytes;
    } catch (e) {
      lastError = e;
      attemptCount++;

      if (!_isRecoverableError(e)) {
        // Don't try next server for validation errors
        rethrow;
      }

      if (attemptCount < urls.length) {
        _tryNextServer();
      }
    }
  }

  throw AllServersFailedException(
    'All servers failed. Last error: $lastError',
    failedServers: urls,
  );
}