|
1 | 1 | #include "tgbot/Api.h" |
2 | 2 |
|
| 3 | +#include <chrono> |
| 4 | +#include <thread> |
| 5 | + |
3 | 6 | namespace TgBot { |
4 | 7 |
|
5 | 8 | Api::Api(std::string token, const HttpClient& httpClient, const std::string& url) |
@@ -2496,20 +2499,25 @@ boost::property_tree::ptree Api::sendRequest(const std::string& method, const st |
2496 | 2499 | url += "/"; |
2497 | 2500 | url += method; |
2498 | 2501 |
|
2499 | | - std::string serverResponse = _httpClient.makeRequest(url, args); |
2500 | | - if (!serverResponse.compare(0, 6, "<html>")) { |
2501 | | - throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token."); |
2502 | | - } |
| 2502 | + while(1) |
| 2503 | + { |
| 2504 | + std::string serverResponse = _httpClient.makeRequest(url, args); |
| 2505 | + if (!serverResponse.compare(0, 6, "<html>")) { |
| 2506 | + throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token."); |
| 2507 | + } |
2503 | 2508 |
|
2504 | | - boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse); |
2505 | | - try { |
2506 | | - if (result.get<bool>("ok", false)) { |
2507 | | - return result.get_child("result"); |
2508 | | - } else { |
2509 | | - throw TgException(result.get("description", "")); |
| 2509 | + boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse); |
| 2510 | + try { |
| 2511 | + if (result.get<bool>("ok", false)) { |
| 2512 | + return result.get_child("result"); |
| 2513 | + } else { |
| 2514 | + std::this_thread::sleep_for(std::chrono::seconds(1)); |
| 2515 | + continue; |
| 2516 | + //throw TgException(result.get("description", "")); |
| 2517 | + } |
| 2518 | + } catch (boost::property_tree::ptree_error& e) { |
| 2519 | + throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what())); |
2510 | 2520 | } |
2511 | | - } catch (boost::property_tree::ptree_error& e) { |
2512 | | - throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what())); |
2513 | 2521 | } |
2514 | 2522 | } |
2515 | 2523 | } |
0 commit comments