From fbbd66edd7fba5c4b15365769296d918624ede80 Mon Sep 17 00:00:00 2001 From: HgO Date: Fri, 25 Nov 2022 18:59:32 +0000 Subject: [PATCH] =?UTF-8?q?Resolve=20"Renvoyer=20l'alerte=20quand=20on=20r?= =?UTF-8?q?e=C3=A7oit=20une=20RoomSendError"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matrix_alertbot/chat_functions.py | 4 ++-- matrix_alertbot/main.py | 8 ++++---- tests/test_chat_functions.py | 6 ++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/matrix_alertbot/chat_functions.py b/matrix_alertbot/chat_functions.py index ab0a5b4..450f2ee 100644 --- a/matrix_alertbot/chat_functions.py +++ b/matrix_alertbot/chat_functions.py @@ -77,7 +77,7 @@ async def send_text_to_room( ) if isinstance(response_event, RoomSendError): - raise SendRetryError(response_event.error) + raise SendRetryError(f"{response_event.status_code} - {response_event.message}") return response_event @@ -120,7 +120,7 @@ async def react_to_event( ) if isinstance(response_event, RoomSendError): - raise SendRetryError(response_event.error) + raise SendRetryError(f"{response_event.status_code} - {response_event.message}") return response_event diff --git a/matrix_alertbot/main.py b/matrix_alertbot/main.py index 345e5d1..28d98fd 100644 --- a/matrix_alertbot/main.py +++ b/matrix_alertbot/main.py @@ -36,16 +36,16 @@ def create_matrix_client(config: Config) -> AsyncClient: # Configuration options for the AsyncClient try: matrix_client_config = AsyncClientConfig( - max_limit_exceeded=0, - max_timeouts=0, + max_limit_exceeded=5, + max_timeouts=3, store_sync_tokens=True, encryption_enabled=True, ) except ImportWarning as e: logger.warning(e) matrix_client_config = AsyncClientConfig( - max_limit_exceeded=0, - max_timeouts=0, + max_limit_exceeded=5, + max_timeouts=3, store_sync_tokens=True, encryption_enabled=False, ) diff --git a/tests/test_chat_functions.py b/tests/test_chat_functions.py index 08d6f4a..e9d82a0 100644 --- a/tests/test_chat_functions.py +++ b/tests/test_chat_functions.py @@ -64,7 +64,8 @@ class ChatFunctionsTestCase(unittest.IsolatedAsyncioTestCase): async def test_react_to_event_return_room_send_error(self) -> None: fake_response = Mock(spec=nio.RoomSendError) - fake_response.error = "some error" + fake_response.message = "some error" + fake_response.status_code = "some status code" fake_matrix_client = Mock(spec=nio.AsyncClient) fake_matrix_client.room_send.return_value = make_awaitable(fake_response) fake_room_id = "!abcdefgh:example.com" @@ -204,7 +205,8 @@ class ChatFunctionsTestCase(unittest.IsolatedAsyncioTestCase): async def test_send_text_to_room_return_room_send_error(self) -> None: fake_response = Mock(spec=nio.RoomSendError) - fake_response.error = "some error" + fake_response.status_code = "some status_code" + fake_response.message = "some error" fake_matrix_client = Mock(spec=nio.AsyncClient) fake_matrix_client.room_send.return_value = make_awaitable(fake_response) fake_room_id = "!abcdefgh:example.com"