From d9e22c6ea85a3f732afbb1f3238bf912b582c584 Mon Sep 17 00:00:00 2001 From: HgO Date: Mon, 22 Jan 2024 11:43:11 +0100 Subject: [PATCH] fix linting and improve logs --- matrix_alertbot/callback.py | 14 +++++++++----- matrix_alertbot/webhook.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/matrix_alertbot/callback.py b/matrix_alertbot/callback.py index f2963e1..89ef4e2 100644 --- a/matrix_alertbot/callback.py +++ b/matrix_alertbot/callback.py @@ -161,16 +161,20 @@ class Callbacks: # Attempt to join 3 times before giving up for attempt in range(3): result = await self.matrix_client.join(room.room_id) - if type(result) == JoinError: + if isinstance(result, JoinError): logger.error( - f"Error joining room {room.room_id} (attempt %d): %s", - attempt, - result.message, + f"Bot {self.matrix_client.user_id} | Room ID {room.room_id} | " + f"Sender {event.sender} | " + f"Error joining room (attempt {attempt}): {result.message}" ) else: break else: - logger.error("Unable to join room: %s", room.room_id) + logger.error( + f"Bot {self.matrix_client.user_id} | Room ID {room.room_id} | " + f"Sender {event.sender} | " + f"Unable to join room" + ) # Successfully joined room logger.info( diff --git a/matrix_alertbot/webhook.py b/matrix_alertbot/webhook.py index fac4860..a003728 100644 --- a/matrix_alertbot/webhook.py +++ b/matrix_alertbot/webhook.py @@ -85,7 +85,7 @@ async def create_alerts(request: web_request.Request) -> web.Response: alert_dicts = data["alerts"] if not isinstance(data["alerts"], list): - alerts_type = type(alert_dicts).__name__ + alerts_type = alert_dicts.__class__.__name__ logger.error(f"Received data with invalid alerts type '{alerts_type}'.") return web.Response( status=400, body=f"Alerts must be a list, got '{alerts_type}'."