From 587ec98f3ef85317ffc7369913707a7d2ca9641c Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 12 Apr 2022 04:17:18 -0400 Subject: [PATCH] Handle serializer errors on connect --- matrix_appservice_kakaotalk/kt/client/client.py | 10 +++++++--- matrix_appservice_kakaotalk/user.py | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index 0267cc5..54191de 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -240,13 +240,17 @@ class Client: self.user.oauth_credential = oauth_info.credential await self.user.save() - async def connect(self) -> LoginResult: + async def connect(self) -> LoginResult | None: """ Start a new talk session by providing a token obtained from a prior login. Receive a snapshot of account state in response. """ - login_result = await self._api_user_request_result(LoginResult, "connect") - assert self.user.ktid == login_result.userId, f"User ID mismatch: expected {self.user.ktid}, got {login_result.userId}" + try: + login_result = await self._api_user_request_result(LoginResult, "connect") + assert self.user.ktid == login_result.userId, f"User ID mismatch: expected {self.user.ktid}, got {login_result.userId}" + except SerializerError: + self.log.exception("Unable to deserialize login result, but connecting anyways") + login_result = None # TODO Skip if handlers are already listening. But this is idempotent and thus probably safe self._start_listen() return login_result diff --git a/matrix_appservice_kakaotalk/user.py b/matrix_appservice_kakaotalk/user.py index cf53342..3bfdbac 100644 --- a/matrix_appservice_kakaotalk/user.py +++ b/matrix_appservice_kakaotalk/user.py @@ -412,7 +412,8 @@ class User(DBUser, BaseUser): try: login_result = await self.client.connect() await self.on_connect() - await self._sync_channels(login_result, sync_count) + if login_result: + await self._sync_channels(login_result, sync_count) return True except AuthenticationRequired as e: await self.send_bridge_notice(