Catch AuthKeyNotFound in start
This commit is contained in:
@@ -23,6 +23,7 @@ import time
|
||||
from telethon.errors import (
|
||||
AuthKeyDuplicatedError,
|
||||
AuthKeyError,
|
||||
AuthKeyNotFound,
|
||||
RPCError,
|
||||
TakeoutInitDelayError,
|
||||
UnauthorizedError,
|
||||
@@ -215,7 +216,7 @@ class User(DBUser, AbstractUser, BaseUser):
|
||||
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"
|
||||
@@ -236,8 +237,8 @@ class User(DBUser, AbstractUser, BaseUser):
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user