From ed24a0b89f1214d2c10dc13b8f6e657a8d96b19e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 25 Apr 2023 19:29:24 +0300 Subject: [PATCH] Handle flood waits in provisioning API code and password steps --- mautrix_telegram/web/common/auth_api.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mautrix_telegram/web/common/auth_api.py b/mautrix_telegram/web/common/auth_api.py index 08b6ffa4..3fba40db 100644 --- a/mautrix_telegram/web/common/auth_api.py +++ b/mautrix_telegram/web/common/auth_api.py @@ -289,6 +289,17 @@ class AuthAPI(abc.ABC): errcode="phone_number_unoccupied", error="That phone number has not been registered.", ) + except FloodWaitError as e: + return self.get_login_response( + mxid=user.mxid, + state="code", + status=429, + errcode="flood_wait", + error=( + "You tried to enter your phone code too many times. " + f"Please wait for {format_duration(e.seconds)} before trying again." + ), + ) except SessionPasswordNeededError: if not password_in_data: if user.command_status and user.command_status["action"] == "Login": @@ -354,6 +365,17 @@ class AuthAPI(abc.ABC): "terminated via the Telegram app." ), ) + except FloodWaitError as e: + return self.get_login_response( + mxid=user.mxid, + state="password", + status=429, + errcode="flood_wait", + error=( + "You tried to enter your password too many times. " + f"Please wait for {format_duration(e.seconds)} before trying again." + ), + ) except Exception as e: self.log.exception("Error sending password") if isinstance(e, ValueError) and "You must provide a phone and a code" in str(e):