diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2023-06-05 01:43:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 01:43:53 +0300 |
commit | f35c7696d73fb725095be82ae8a982d14283686a (patch) | |
tree | b2e0e4fdebeff72d3d2cc9dc5f245e97e39a8a23 /src | |
parent | 9343618bdea96942c86fa8fc927a28f2885550af (diff) |
Revert "Repeat the http request on fail"
Diffstat (limited to 'src')
-rw-r--r-- | src/Api.cpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index f238a70..7bd9e64 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1,8 +1,5 @@ #include "tgbot/Api.h" -#include <chrono> -#include <thread> - namespace TgBot { Api::Api(std::string token, const HttpClient& httpClient, const std::string& url) @@ -2507,36 +2504,20 @@ boost::property_tree::ptree Api::sendRequest(const std::string& method, const st url += "/"; url += method; - int requestRetryBackoff = _httpClient.getRequestBackoff(); - int retries = 0; - while (1) - { - try { - 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", "")); - } - } 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; - } + 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", "")); } + } catch (boost::property_tree::ptree_error& e) { + throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what())); } } } |