handle generic exceptions
This commit is contained in:
parent
c34a823c35
commit
a08cd69171
1 changed files with 10 additions and 2 deletions
|
@ -70,7 +70,7 @@ async def create_alerts(request: web_request.Request) -> web.Response:
|
||||||
config: Config = request.app["config"]
|
config: Config = request.app["config"]
|
||||||
|
|
||||||
if room_id not in config.allowed_rooms:
|
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(
|
return web.Response(
|
||||||
status=401, body=f"Cannot send alerts to room ID {room_id}."
|
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:
|
except (SendRetryError, LocalProtocolError, ClientError) as e:
|
||||||
logger.error(
|
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(
|
return web.Response(
|
||||||
status=500,
|
status=500,
|
||||||
body=f"An error occured when sending alert with fingerprint '{alert.fingerprint}' to Matrix room.",
|
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)
|
return web.Response(status=200)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue