Add Global::is_expected_error.

GitOrigin-RevId: afa4741a772ad99844195a583ee40d3fc50fef4f
This commit is contained in:
levlam 2020-03-31 00:22:52 +03:00
parent f432d403e7
commit 4cfb7c56d2
3 changed files with 16 additions and 19 deletions

View File

@ -9641,19 +9641,11 @@ tl_object_ptr<td_api::chatMember> ContactsManager::get_chat_member_object(
bool ContactsManager::on_get_channel_error(ChannelId channel_id, const Status &status, const string &source) {
LOG(INFO) << "Receive " << status << " in " << channel_id << " from " << source;
if (status.code() == 401) {
// authorization is lost
return true;
}
if (status.code() == 420 || status.code() == 429) {
// flood wait
return true;
}
if (status.message() == CSlice("BOT_METHOD_INVALID")) {
LOG(ERROR) << "Receive BOT_METHOD_INVALID from " << source;
return true;
}
if (G()->close_flag()) {
if (G()->is_expected_error(status)) {
return true;
}
if (status.message() == "CHANNEL_PRIVATE" || status.message() == "CHANNEL_PUBLIC_GROUP_NA") {
@ -9675,7 +9667,7 @@ bool ContactsManager::on_get_channel_error(ChannelId channel_id, const Status &s
auto debug_channel_object = oneline(to_string(get_supergroup_object(channel_id, c)));
if (c->status.is_member()) {
LOG(INFO) << "Emulate leaving " << channel_id;
// TODO we also may try to write to public channel
// TODO we also may try to write to a public channel
int32 flags = 0;
if (c->is_megagroup) {
flags |= CHANNEL_FLAG_IS_MEGAGROUP;

View File

@ -343,6 +343,19 @@ class Global : public ActorContext {
return close_flag_.load();
}
bool is_expected_error(const Status &error) const {
CHECK(error.is_error());
if (error.code() == 401) {
// authorization is lost
return true;
}
if (error.code() == 420 || error.code() == 429) {
// flood wait
return true;
}
return close_flag();
}
const std::vector<std::shared_ptr<NetStatsCallback>> &get_net_stats_file_callbacks() {
return net_stats_file_callbacks_;
}

View File

@ -21413,19 +21413,11 @@ bool MessagesManager::on_update_scheduled_message_id(int64 random_id, ScheduledS
}
bool MessagesManager::on_get_dialog_error(DialogId dialog_id, const Status &status, const string &source) {
if (status.code() == 401) {
// authorization is lost
return true;
}
if (status.code() == 420 || status.code() == 429) {
// flood wait
return true;
}
if (status.message() == CSlice("BOT_METHOD_INVALID")) {
LOG(ERROR) << "Receive BOT_METHOD_INVALID from " << source;
return true;
}
if (G()->close_flag()) {
if (G()->is_expected_error(status)) {
return true;
}