slightly better error handling
This commit is contained in:
parent
2af5f1d00b
commit
94f6a58f74
15
commands.cpp
15
commands.cpp
@ -39,7 +39,7 @@ void cmd::handle_regular_message(context *ctx, td_api::message &msg) {
|
||||
nullptr /*reply_to*/, nullptr /*options*/,
|
||||
nullptr, // reply_markup
|
||||
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
|
||||
std::move(td_api::make_object<td_api::formattedText>(url, std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))),
|
||||
std::move(td_api::make_object<td_api::formattedText>(!url.empty() ? url : "error :(", std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))),
|
||||
nullptr /*link_preview_options*/, false /*clear_draft*/
|
||||
))
|
||||
), {});
|
||||
@ -50,7 +50,7 @@ void cmd::handle_regular_message(context *ctx, td_api::message &msg) {
|
||||
nullptr /*reply_to*/, nullptr /*options*/,
|
||||
nullptr, // reply_markup
|
||||
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
|
||||
std::move(td_api::make_object<td_api::formattedText>("произошла какая-то ошибка :(", std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))),
|
||||
std::move(td_api::make_object<td_api::formattedText>("error :(", std::move(std::vector<td_api::object_ptr<td_api::textEntity>>()))),
|
||||
nullptr /*link_preview_options*/, false /*clear_draft*/
|
||||
))
|
||||
), {});
|
||||
@ -137,7 +137,7 @@ void cmd::handle_callback_query(context *ctx, td_api::updateNewInlineCallbackQue
|
||||
nullptr, // reply_markup
|
||||
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
|
||||
td_api::make_object<td_api::formattedText>(
|
||||
url,
|
||||
!url.empty() ? url : "error :(",
|
||||
std::move(std::vector<td_api::object_ptr<td_api::textEntity>>())
|
||||
),
|
||||
td_api::make_object<td_api::linkPreviewOptions>(true, "", false, false, false),
|
||||
@ -171,7 +171,7 @@ void cmd::handle_chosen_inline_result(context *ctx, td_api::updateNewChosenInlin
|
||||
nullptr, // reply_markup
|
||||
static_cast<td_api::object_ptr<td_api::InputMessageContent>>(td_api::make_object<td_api::inputMessageText>(
|
||||
td_api::make_object<td_api::formattedText>(
|
||||
url,
|
||||
!url.empty() ? url : "error :(",
|
||||
std::move(std::vector<td_api::object_ptr<td_api::textEntity>>())
|
||||
),
|
||||
td_api::make_object<td_api::linkPreviewOptions>(true, "", false, false, false),
|
||||
@ -198,9 +198,16 @@ bool cmd::shorten_link(std::string link, context *ctx, std::function<void(std::s
|
||||
curl_easy_setopt(req, CURLOPT_PRIVATE, ctx);
|
||||
curl_easy_setopt(req, CURLOPT_FOLLOWLOCATION, 1);
|
||||
ctx->requests.emplace(req, [cb, req, ctx](active_request &r){
|
||||
long statusCode;
|
||||
curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &statusCode);
|
||||
if (statusCode == 200) {
|
||||
std::string shortenedUrl(r.receivedData.data(), r.receivedData.size());
|
||||
spdlog::info("Received data from HTTP server: {}", shortenedUrl);
|
||||
cb(shortenedUrl);
|
||||
} else {
|
||||
spdlog::error("Shortener returned error: {}", statusCode);
|
||||
cb("");
|
||||
}
|
||||
ctx->requests.erase(req);
|
||||
});
|
||||
CURLMcode r = curl_multi_add_handle(ctx->curl, req);
|
||||
|
Loading…
Reference in New Issue
Block a user