Add retry support for failed LP requests
This commit is contained in:
parent
7879ec07be
commit
48518fc076
@ -257,26 +257,33 @@ std::optional<std::string> launchpad::api_get(const std::string& endpoint, const
|
|||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||||
|
|
||||||
CURLcode res = curl_easy_perform(curl);
|
bool tries = 0;
|
||||||
long http_code = 0;
|
long http_code = 0;
|
||||||
if (res != CURLE_OK) {
|
|
||||||
std::cerr << "CURL GET error: " << curl_easy_strerror(res) << std::endl;
|
while (tries < 5) {
|
||||||
|
tries++;
|
||||||
|
CURLcode res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
std::cerr << "CURL GET error: " << curl_easy_strerror(res) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||||
|
curl_slist_free_all(headers);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (http_code >= 400) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return readBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
std::cerr << "HTTP GET request to " << url << " failed with code: " << http_code << "\nResponse: " << readBuffer << std::endl;
|
||||||
curl_slist_free_all(headers);
|
return std::nullopt;
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
|
|
||||||
if (res != CURLE_OK) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (http_code >= 400) {
|
|
||||||
std::cerr << "HTTP GET request to " << url << " failed with code: " << http_code << "\nResponse: " << readBuffer << std::endl;
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
return readBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> launchpad::api_post(
|
std::optional<std::string> launchpad::api_post(
|
||||||
@ -327,26 +334,32 @@ std::optional<std::string> launchpad::api_post(
|
|||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||||
|
|
||||||
CURLcode res = curl_easy_perform(curl);
|
bool tries = 0;
|
||||||
long http_code = 0;
|
long http_code = 0;
|
||||||
if (res != CURLE_OK) {
|
|
||||||
std::cerr << "CURL POST error: " << curl_easy_strerror(res) << std::endl;
|
while (tries < 5) {
|
||||||
|
tries++;
|
||||||
|
CURLcode res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
std::cerr << "CURL POST error: " << curl_easy_strerror(res) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||||
|
curl_slist_free_all(headers);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (http_code >= 400) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return readBuffer;
|
||||||
}
|
}
|
||||||
|
std::cerr << "HTTP POST request to " << url << " failed with code: " << http_code << "\nResponse: " << readBuffer << std::endl;
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
return std::nullopt;
|
||||||
curl_slist_free_all(headers);
|
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
|
|
||||||
if (res != CURLE_OK) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (http_code >= 400) {
|
|
||||||
std::cerr << "HTTP POST request to " << url << " failed with code: " << http_code << "\nResponse: " << readBuffer << std::endl;
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
|
|
||||||
return readBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> launchpad::api_patch(const std::string& endpoint, const nlohmann::json& data) {
|
std::optional<std::string> launchpad::api_patch(const std::string& endpoint, const nlohmann::json& data) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user