post method
Make an HTTP POST request with failover support
Implementation
Future<List<int>> post(String path, List<int> data) async {
int attemptCount = 0;
Object? lastError;
while (attemptCount < urls.length) {
try {
final url = _buildUrl(workingUrl, path);
final response = await _httpClient
.post(
url,
body: data,
headers: {'Content-Type': 'application/x-protobuf'},
)
.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,
);
}