From e3d2a1fceff67754853b0e8cbe5fcb3303ef64aa Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 2 Jan 2023 17:46:54 +0200 Subject: [PATCH] Catch ValueErrors in 2fa login step --- mautrix_telegram/web/common/auth_api.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mautrix_telegram/web/common/auth_api.py b/mautrix_telegram/web/common/auth_api.py index 79540783..5da82d3f 100644 --- a/mautrix_telegram/web/common/auth_api.py +++ b/mautrix_telegram/web/common/auth_api.py @@ -341,8 +341,16 @@ class AuthAPI(abc.ABC): errcode="password_invalid", error="Incorrect password.", ) - except Exception: + 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): + return self.get_login_response( + mxid=user.mxid, + state="request", + status=400, + errcode="phone_code_not_entered", + error="Please request a new phone code and enter it first.", + ) return self.get_login_response( mxid=user.mxid, state="password",