fix linting and improve logs

This commit is contained in:
HgO 2024-01-22 11:43:11 +01:00
parent 86aa44b260
commit d9e22c6ea8
2 changed files with 10 additions and 6 deletions

View file

@ -161,16 +161,20 @@ class Callbacks:
# Attempt to join 3 times before giving up # Attempt to join 3 times before giving up
for attempt in range(3): for attempt in range(3):
result = await self.matrix_client.join(room.room_id) result = await self.matrix_client.join(room.room_id)
if type(result) == JoinError: if isinstance(result, JoinError):
logger.error( logger.error(
f"Error joining room {room.room_id} (attempt %d): %s", f"Bot {self.matrix_client.user_id} | Room ID {room.room_id} | "
attempt, f"Sender {event.sender} | "
result.message, f"Error joining room (attempt {attempt}): {result.message}"
) )
else: else:
break break
else: 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 # Successfully joined room
logger.info( logger.info(

View file

@ -85,7 +85,7 @@ async def create_alerts(request: web_request.Request) -> web.Response:
alert_dicts = data["alerts"] alert_dicts = data["alerts"]
if not isinstance(data["alerts"], list): 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}'.") logger.error(f"Received data with invalid alerts type '{alerts_type}'.")
return web.Response( return web.Response(
status=400, body=f"Alerts must be a list, got '{alerts_type}'." status=400, body=f"Alerts must be a list, got '{alerts_type}'."