Merge branch '9-meilleure-gestion-des-exceptions-pour-le-serveur-http' into 'master'

Resolve "Meilleure gestion des exceptions pour le serveur HTTP"

Closes #9

See merge request Neutrinet/matrix-alertbot!8
This commit is contained in:
HgO 2023-01-29 20:48:33 +00:00
commit 6cfdf342e6

View file

@ -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)