Skip to content

Commit

Permalink
Propagate account being logged-out errors
Browse files Browse the repository at this point in the history
Should close #4016.
  • Loading branch information
Lonami committed Jan 11, 2023
1 parent c932d79 commit fb97a8a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions telethon/client/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ async def catch_up(self: 'TelegramClient'):
# region Private methods

async def _update_loop(self: 'TelegramClient'):
# If the MessageBox is not empty, the account had to be logged-in to fill in its state.
# This flag is used to propagate the "you got logged-out" error up (but getting logged-out
# can only happen if it was once logged-in).
was_once_logged_in = self._authorized is True or not self._message_box.is_empty()

self._updates_error = None
try:
if self._catch_up:
Expand Down Expand Up @@ -289,6 +294,10 @@ async def _update_loop(self: 'TelegramClient'):
# Not logged in or broken authorization key, can't get difference
self._log[__name__].info('Cannot get difference since the account is not logged in: %s', type(e).__name__)
self._message_box.end_difference()
if was_once_logged_in:
self._updates_error = e
await self.disconnect()
break
continue
except OSError as e:
# Network is likely down, but it's unclear for how long.
Expand All @@ -309,12 +318,26 @@ async def _update_loop(self: 'TelegramClient'):
self._log[__name__].debug('Getting difference for channel %s updates', get_diff.channel.channel_id)
try:
diff = await self(get_diff)
except (errors.UnauthorizedError, errors.AuthKeyError) as e:
# Not logged in or broken authorization key, can't get difference
self._log[__name__].warning(
'Cannot get difference for channel %s since the account is not logged in: %s',
get_diff.channel.channel_id, type(e).__name__
)
self._message_box.end_channel_difference(
get_diff,
PrematureEndReason.TEMPORARY_SERVER_ISSUES,
self._mb_entity_cache
)
if was_once_logged_in:
self._updates_error = e
await self.disconnect()
break
continue
except (
errors.PersistentTimestampOutdatedError,
errors.PersistentTimestampInvalidError,
errors.ServerError,
errors.UnauthorizedError,
errors.AuthKeyError,
ValueError
) as e:
# According to Telegram's docs:
Expand Down

0 comments on commit fb97a8a

Please sign in to comment.