summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Api.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index b6dba9a..202fb73 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -2503,27 +2503,31 @@ boost::property_tree::ptree Api::sendRequest(const std::string& method, const st
int retries = 0;
while (1)
{
- std::string serverResponse = _httpClient.makeRequest(url, args);
- if (!serverResponse.compare(0, 6, "<html>")) {
- throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token.");
- }
-
- boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse);
try {
- if (result.get<bool>("ok", false)) {
- return result.get_child("result");
- } else {
- if (retries == _httpClient.getRequestMaxRetries()) {
+ std::string serverResponse = _httpClient.makeRequest(url, args);
+ if (!serverResponse.compare(0, 6, "<html>")) {
+ throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token.");
+ }
+
+ boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse);
+ try {
+ if (result.get<bool>("ok", false)) {
+ return result.get_child("result");
+ } else {
throw TgException(result.get("description", ""));
}
- else {
- std::this_thread::sleep_for(std::chrono::seconds(requestRetryBackoff));
- retries++;
- continue;
- }
+ } catch (boost::property_tree::ptree_error& e) {
+ throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what()));
+ }
+ } catch (...) {
+ int max_retries = _httpClient.getRequestMaxRetries();
+ if ((max_retries >= 0) && (retries == max_retries)) {
+ throw;
+ } else {
+ std::this_thread::sleep_for(std::chrono::seconds(requestRetryBackoff));
+ retries++;
+ continue;
}
- } catch (boost::property_tree::ptree_error& e) {
- throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what()));
}
}
}