From d842fc73cbd120ea0e0bfa47d45a20306f16c1d2 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 16 Feb 2019 23:21:47 +0200 Subject: [PATCH] Handle AuthKeyError when terminating sessions --- mautrix_telegram/commands/telegram/account.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mautrix_telegram/commands/telegram/account.py b/mautrix_telegram/commands/telegram/account.py index bfb71b37..ca2e69c3 100644 --- a/mautrix_telegram/commands/telegram/account.py +++ b/mautrix_telegram/commands/telegram/account.py @@ -17,7 +17,7 @@ from typing import Dict, Optional from telethon.errors import (UsernameInvalidError, UsernameNotModifiedError, UsernameOccupiedError, - HashInvalidError) + HashInvalidError, AuthKeyError) from telethon.tl.types import Authorization from telethon.tl.functions.account import (UpdateUsernameRequest, GetAuthorizationsRequest, ResetAuthorizationRequest) @@ -94,6 +94,11 @@ async def session(evt: CommandEvent) -> Optional[Dict]: ok = await evt.sender.client(ResetAuthorizationRequest(hash=session_hash)) except HashInvalidError: return await evt.reply("Invalid session hash.") + except AuthKeyError as e: + if e.message == "FRESH_RESET_AUTHORISATION_FORBIDDEN": + return await evt.reply("New sessions can't terminate other sessions. " + "Please wait a while.") + raise if ok: return await evt.reply("Session terminated successfully.") else: