|
1 | 1 | #include "tgbot/Api.h" |
2 | 2 |
|
3 | | -#include <chrono> |
4 | | -#include <thread> |
5 | | - |
6 | 3 | namespace TgBot { |
7 | 4 |
|
8 | 5 | 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 |
2507 | 2504 | url += "/"; |
2508 | 2505 | url += method; |
2509 | 2506 |
|
2510 | | - int requestRetryBackoff = _httpClient.getRequestBackoff(); |
2511 | | - int retries = 0; |
2512 | | - while (1) |
2513 | | - { |
2514 | | - try { |
2515 | | - std::string serverResponse = _httpClient.makeRequest(url, args); |
2516 | | - if (!serverResponse.compare(0, 6, "<html>")) { |
2517 | | - throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token."); |
2518 | | - } |
2519 | | - |
2520 | | - boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse); |
2521 | | - try { |
2522 | | - if (result.get<bool>("ok", false)) { |
2523 | | - return result.get_child("result"); |
2524 | | - } else { |
2525 | | - throw TgException(result.get("description", "")); |
2526 | | - } |
2527 | | - } catch (boost::property_tree::ptree_error& e) { |
2528 | | - throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what())); |
2529 | | - } |
2530 | | - } catch (...) { |
2531 | | - int max_retries = _httpClient.getRequestMaxRetries(); |
2532 | | - if ((max_retries >= 0) && (retries == max_retries)) { |
2533 | | - throw; |
2534 | | - } else { |
2535 | | - std::this_thread::sleep_for(std::chrono::seconds(requestRetryBackoff)); |
2536 | | - retries++; |
2537 | | - continue; |
2538 | | - } |
| 2507 | + std::string serverResponse = _httpClient.makeRequest(url, args); |
| 2508 | + if (!serverResponse.compare(0, 6, "<html>")) { |
| 2509 | + throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token."); |
| 2510 | + } |
| 2511 | + |
| 2512 | + boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse); |
| 2513 | + try { |
| 2514 | + if (result.get<bool>("ok", false)) { |
| 2515 | + return result.get_child("result"); |
| 2516 | + } else { |
| 2517 | + throw TgException(result.get("description", "")); |
2539 | 2518 | } |
| 2519 | + } catch (boost::property_tree::ptree_error& e) { |
| 2520 | + throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what())); |
2540 | 2521 | } |
2541 | 2522 | } |
2542 | 2523 | } |
0 commit comments