Skip to content

Commit

Permalink
Properly handle PhoneCodeExpiredError in sign_in
Browse files Browse the repository at this point in the history
Should actually fix #3185 now.
  • Loading branch information
Lonami committed Apr 6, 2023
1 parent 10c74f8 commit 5b11357
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions telethon/client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,9 @@ async def sign_in(

# May raise PhoneCodeEmptyError, PhoneCodeExpiredError,
# PhoneCodeHashEmptyError or PhoneCodeInvalidError.
try:
request = functions.auth.SignInRequest(
phone, phone_code_hash, str(code)
)
except errors.PhoneCodeExpiredError:
self._phone_code_hash.pop(phone, None)
request = functions.auth.SignInRequest(
phone, phone_code_hash, str(code)
)
elif password:
pwd = await self(functions.account.GetPasswordRequest())
request = functions.auth.CheckPasswordRequest(
Expand All @@ -355,7 +352,12 @@ async def sign_in(
'and a password only if an RPCError was raised before.'
)

result = await self(request)
try:
result = await self(request)
except errors.PhoneCodeExpiredError:
self._phone_code_hash.pop(phone, None)
raise

if isinstance(result, types.auth.AuthorizationSignUpRequired):
# Emulate pre-layer 104 behaviour
self._tos = result.terms_of_service
Expand Down
2 changes: 1 addition & 1 deletion telethon/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Versions should comply with PEP440.
# This line is parsed in setup.py:
__version__ = '1.28.0'
__version__ = '1.28.1'

0 comments on commit 5b11357

Please sign in to comment.