You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure whether the timeout is caused by network oddities, or by the Telegram server behavior. In any case, timeout should be an expected event. For this reason, throwing an exception is this case seems to be a doubtful design. In order to handle the timeout, one needs to derive another HttpRequest class and silence the exception, for example like this:
// Derive our own http client to handle the exceptions // produced inside the library. classMyHttpClient : publicTgBot::CurlHttpClient
{
std::string makeRequest(const TgBot::Url& url, const std::vector<TgBot::HttpReqArg>& args) constoverride
{
// Repeat, until the request is successful. while (1)
{
try
{
returnTgBot::CurlHttpClient::makeRequest(url, args);
}
catch (std::runtime_error& e)
{
fprintf(stderr, "Error: %s\n", e.what());
}
// Wait a moment for the potential network issue to get resolved, // and try again. std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
};
staticauto& getHttpClient()
{
static MyHttpClient instance;
return instance;
}
...
TgBot::Bot bot(token, getHttpClient());
I don't have any alternative suggestion, atm. Could you please share your thoughts and experiences? Thanks!
The text was updated successfully, but these errors were encountered:
Just now, 3 variations spontaneously come to my mind. The first would be to make your own derived class and handle the error that way. Like you did it.
Or you could automatically ignore certain errors directly in the library so that they are never thrown. But then it could be that someone would like to handle this error instead of ignoring it.
Or the user can use some function to specify which errors should (not) be thrown or how extensively errors should be thrown.
Now the question is, what makes the most sense or if there are other better options?
Dear TgBot authors, greetings,
Here is a feedback from using TgBot in a production workload. Once in every few hours I get timeout of the http resuest, like this:
In the present code design, everything what is not an OK status throws an exception:
I'm not sure whether the timeout is caused by network oddities, or by the Telegram server behavior. In any case, timeout should be an expected event. For this reason, throwing an exception is this case seems to be a doubtful design. In order to handle the timeout, one needs to derive another HttpRequest class and silence the exception, for example like this:
I don't have any alternative suggestion, atm. Could you please share your thoughts and experiences? Thanks!
The text was updated successfully, but these errors were encountered: