Skip to content

Commit

Permalink
Catch AuthKeyNotFound in start
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Oct 22, 2023
1 parent 060dd64 commit 6fafc53
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mautrix_telegram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from telethon.errors import (
AuthKeyDuplicatedError,
AuthKeyError,
AuthKeyNotFound,
RPCError,
TakeoutInitDelayError,
UnauthorizedError,
Expand Down Expand Up @@ -215,7 +216,7 @@ async def ensure_started(self, even_if_no_session=False) -> User:
async with self._ensure_started_lock:
return cast(User, await super().ensure_started(even_if_no_session))

async def on_signed_out(self, err: UnauthorizedError | AuthKeyError) -> None:
async def on_signed_out(self, err: UnauthorizedError | AuthKeyError | AuthKeyNotFound) -> None:
error_code = "tg-auth-error"
if isinstance(err, AuthKeyDuplicatedError):
error_code = "tg-auth-key-duplicated"
Expand All @@ -236,8 +237,8 @@ async def on_signed_out(self, err: UnauthorizedError | AuthKeyError) -> None:
async def start(self, delete_unless_authenticated: bool = False) -> User:
try:
await super().start()
except AuthKeyDuplicatedError as e:
self.log.warning("Got AuthKeyDuplicatedError in start()")
except (AuthKeyDuplicatedError, AuthKeyNotFound) as e:
self.log.warning(f"Got {type(e).__name__} in start()")
await self.on_signed_out(e)
if not delete_unless_authenticated:
# The caller wants the client to be connected, so restart the connection.
Expand Down

0 comments on commit 6fafc53

Please sign in to comment.