diff --git a/matrix_appservice_kakaotalk/kt/client/client.py b/matrix_appservice_kakaotalk/kt/client/client.py index 390e472..d502ccc 100644 --- a/matrix_appservice_kakaotalk/kt/client/client.py +++ b/matrix_appservice_kakaotalk/kt/client/client.py @@ -22,7 +22,7 @@ with any other potential backend. from __future__ import annotations -from typing import TYPE_CHECKING, cast, Type, Optional, Union +from typing import TYPE_CHECKING, cast, Awaitable, Type, Optional, Union import asyncio from contextlib import asynccontextmanager import logging @@ -423,6 +423,9 @@ class Client: self._stop_listen() await self.user.on_disconnect(res) + def _on_error(self, data: dict[str, JSON]) -> Awaitable[None]: + return self.user.on_error(data) + def _start_listen(self) -> None: self._add_event_handler("chat", self._on_chat) @@ -430,6 +433,7 @@ class Client: # TODO many more listeners self._add_event_handler("disconnected", self._on_listen_disconnect) self._add_event_handler("switch_server", self._on_switch_server) + self._add_event_handler("error", self._on_error) def _stop_listen(self) -> None: for method in self._handler_methods: diff --git a/matrix_appservice_kakaotalk/user.py b/matrix_appservice_kakaotalk/user.py index 6257bc1..180eee0 100644 --- a/matrix_appservice_kakaotalk/user.py +++ b/matrix_appservice_kakaotalk/user.py @@ -22,6 +22,7 @@ import time from mautrix.bridge import BaseUser, async_getter_lock from mautrix.types import ( EventID, + JSON, MessageType, RoomID, TextMessageEventContent, @@ -633,6 +634,14 @@ class User(DBUser, BaseUser): await self.logout() await self.send_bridge_notice(f"Disconnected from KakaoTalk: {reason_str} {reason_suffix}") + def on_error(self, error: JSON) -> Awaitable[None]: + return self.send_bridge_notice( + f"Got error event from KakaoTalk:\n\n> {error}", + # TODO Which error code to use? + #error_code="kt-connection-error", + error_message=str(error), + ) + async def on_client_disconnect(self) -> None: self.is_connected = False self._track_metric(METRIC_CONNECTED, False) diff --git a/node/src/client.js b/node/src/client.js index 4c40ae3..4e62242 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -135,6 +135,13 @@ class UserClient { is_sequential: true, }) }) + + this.#talkClient.on("error", (err) => { + this.log(`Client error: ${err}`) + return this.write("error", { + error: err, + }) + }) } /**