mirror of
https://github.com/PaiGramTeam/telegram-bot-api.git
synced 2024-11-22 23:42:28 +00:00
Add and use Client::get_closing_error().
This commit is contained in:
parent
9aeb8135e0
commit
ed9f836977
@ -4633,12 +4633,9 @@ void Client::get_chat_member(int64 chat_id, int64 user_id, PromisedQueryPtr quer
|
||||
}
|
||||
|
||||
void Client::send_request(object_ptr<td_api::Function> &&f, td::unique_ptr<TdQueryCallback> handler) {
|
||||
if (logging_out_) {
|
||||
return handler->on_result(
|
||||
make_object<td_api::error>(LOGGING_OUT_ERROR_CODE, get_logging_out_error_description().str()));
|
||||
}
|
||||
if (closing_) {
|
||||
return handler->on_result(make_object<td_api::error>(CLOSING_ERROR_CODE, CLOSING_ERROR_DESCRIPTION.str()));
|
||||
if (closing_ || logging_out_) {
|
||||
auto error = get_closing_error();
|
||||
return handler->on_result(make_object<td_api::error>(error.code, error.message.str()));
|
||||
}
|
||||
|
||||
do_send_request(std::move(f), std::move(handler));
|
||||
@ -4671,13 +4668,12 @@ void Client::on_update_file(object_ptr<td_api::file> file) {
|
||||
}
|
||||
if (!file->local_->is_downloading_active_ && download_started_file_ids_.count(file_id)) {
|
||||
// also includes all 5xx and 429 errors
|
||||
if (closing_ || logging_out_) {
|
||||
auto error = get_closing_error();
|
||||
return on_file_download(file_id, Status::Error(error.code, error.message));
|
||||
}
|
||||
|
||||
auto error = Status::Error(400, "Bad Request: wrong file_id or the file is temporarily unavailable");
|
||||
if (logging_out_) {
|
||||
error = Status::Error(LOGGING_OUT_ERROR_CODE, get_logging_out_error_description());
|
||||
}
|
||||
if (closing_) {
|
||||
error = Status::Error(CLOSING_ERROR_CODE, CLOSING_ERROR_DESCRIPTION);
|
||||
}
|
||||
return on_file_download(file_id, std::move(error));
|
||||
}
|
||||
}
|
||||
@ -5128,10 +5124,6 @@ void Client::on_result(td::uint64 id, object_ptr<td_api::Object> result) {
|
||||
handlers_.erase(id);
|
||||
}
|
||||
|
||||
td::Slice Client::get_logging_out_error_description() const {
|
||||
return is_api_id_invalid_ ? API_ID_INVALID_ERROR_DESCRIPTION : LOGGING_OUT_ERROR_DESCRIPTION;
|
||||
}
|
||||
|
||||
void Client::on_closed() {
|
||||
LOG(WARNING) << "Closed";
|
||||
CHECK(logging_out_ || closing_);
|
||||
@ -9331,14 +9323,26 @@ void Client::fail_query_conflict(Slice message, PromisedQueryPtr &&query) {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::fail_query_closing(PromisedQueryPtr &&query) const {
|
||||
void Client::fail_query_closing(PromisedQueryPtr &&query) {
|
||||
auto error = get_closing_error();
|
||||
fail_query(error.code, error.message, std::move(query));
|
||||
}
|
||||
|
||||
Client::ClosingError Client::get_closing_error() {
|
||||
ClosingError result;
|
||||
if (logging_out_) {
|
||||
return fail_query(LOGGING_OUT_ERROR_CODE, get_logging_out_error_description(), std::move(query));
|
||||
result.code = 401;
|
||||
if (is_api_id_invalid_) {
|
||||
result.message = Slice("Unauthorized: invalid api-id/api-hash");
|
||||
} else {
|
||||
result.message = Slice("Unauthorized");
|
||||
}
|
||||
} else {
|
||||
CHECK(closing_);
|
||||
result.code = 500;
|
||||
result.message = Slice("Internal Server Error: restart");
|
||||
}
|
||||
if (closing_) {
|
||||
return fail_query(CLOSING_ERROR_CODE, CLOSING_ERROR_DESCRIPTION, std::move(query));
|
||||
}
|
||||
UNREACHABLE();
|
||||
return result;
|
||||
}
|
||||
|
||||
class Client::JsonUpdates final : public Jsonable {
|
||||
@ -10940,13 +10944,6 @@ constexpr Client::Slice Client::GREAT_MINDS_SET_NAME;
|
||||
|
||||
constexpr Client::Slice Client::MASK_POINTS[MASK_POINTS_SIZE];
|
||||
|
||||
constexpr int Client::LOGGING_OUT_ERROR_CODE;
|
||||
constexpr Client::Slice Client::LOGGING_OUT_ERROR_DESCRIPTION;
|
||||
constexpr Client::Slice Client::API_ID_INVALID_ERROR_DESCRIPTION;
|
||||
|
||||
constexpr int Client::CLOSING_ERROR_CODE;
|
||||
constexpr Client::Slice Client::CLOSING_ERROR_DESCRIPTION;
|
||||
|
||||
td::FlatHashMap<td::string, td::Status (Client::*)(PromisedQueryPtr &query)> Client::methods_;
|
||||
|
||||
} // namespace telegram_bot_api
|
||||
|
@ -84,13 +84,6 @@ class Client final : public WebhookActor::Callback {
|
||||
static constexpr int32 MAX_LENGTH = 10000; // max width or height
|
||||
static constexpr int32 MAX_DURATION = 24 * 60 * 60;
|
||||
|
||||
static constexpr int LOGGING_OUT_ERROR_CODE = 401;
|
||||
static constexpr Slice LOGGING_OUT_ERROR_DESCRIPTION = "Unauthorized";
|
||||
static constexpr Slice API_ID_INVALID_ERROR_DESCRIPTION = "Unauthorized: invalid api-id/api-hash";
|
||||
|
||||
static constexpr int CLOSING_ERROR_CODE = 500;
|
||||
static constexpr Slice CLOSING_ERROR_DESCRIPTION = "Internal Server Error: restart";
|
||||
|
||||
class JsonFile;
|
||||
class JsonDatedFile;
|
||||
class JsonDatedFiles;
|
||||
@ -316,7 +309,6 @@ class Client final : public WebhookActor::Callback {
|
||||
|
||||
void on_update_authorization_state();
|
||||
void log_out(bool is_api_id_invalid);
|
||||
Slice get_logging_out_error_description() const;
|
||||
void on_closed();
|
||||
void finish_closing();
|
||||
|
||||
@ -615,10 +607,16 @@ class Client final : public WebhookActor::Callback {
|
||||
|
||||
void abort_long_poll(bool from_set_webhook);
|
||||
|
||||
void fail_query_closing(PromisedQueryPtr &&query) const;
|
||||
void fail_query_closing(PromisedQueryPtr &&query);
|
||||
|
||||
void fail_query_conflict(Slice message, PromisedQueryPtr &&query);
|
||||
|
||||
struct ClosingError {
|
||||
int code;
|
||||
Slice message;
|
||||
};
|
||||
ClosingError get_closing_error();
|
||||
|
||||
static int get_retry_after_time(Slice error_message);
|
||||
|
||||
static void fail_query_with_error(PromisedQueryPtr query, int32 error_code, Slice error_message,
|
||||
|
Loading…
Reference in New Issue
Block a user