From a08cd6917173514bbc474aeaf698a749d93e5175 Mon Sep 17 00:00:00 2001 From: HgO Date: Sun, 29 Jan 2023 21:44:24 +0100 Subject: [PATCH] handle generic exceptions --- matrix_alertbot/webhook.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/matrix_alertbot/webhook.py b/matrix_alertbot/webhook.py index b093343..7443d9a 100644 --- a/matrix_alertbot/webhook.py +++ b/matrix_alertbot/webhook.py @@ -70,7 +70,7 @@ async def create_alerts(request: web_request.Request) -> web.Response: config: Config = request.app["config"] if room_id not in config.allowed_rooms: - logger.error("Cannot send alerts to room ID {room_id}.") + logger.error(f"Cannot send alerts to room ID {room_id}.") return web.Response( status=401, body=f"Cannot send alerts to room ID {room_id}." ) @@ -115,12 +115,20 @@ async def create_alerts(request: web_request.Request) -> web.Response: ) except (SendRetryError, LocalProtocolError, ClientError) as e: logger.error( - f"Unable to send alert {alert.fingerprint} to Matrix room: {e}" + f"Unable to send alert {alert.fingerprint} to Matrix room {room_id}: {e}" ) return web.Response( status=500, body=f"An error occured when sending alert with fingerprint '{alert.fingerprint}' to Matrix room.", ) + except Exception as e: + logger.error( + f"Unable to send alert {alert.fingerprint} to Matrix room {room_id}: {e}" + ) + return web.Response( + status=500, + body=f"An exception occured when sending alert with fingerprint '{alert.fingerprint}' to Matrix room.", + ) return web.Response(status=200)