From d956760e4c93c98ec28ebfa96e8292adfb68823a Mon Sep 17 00:00:00 2001 From: deflax Date: Sat, 20 Jan 2024 01:47:23 +0200 Subject: [PATCH] catch database connection errors --- src/discordbot/discordbot.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/discordbot/discordbot.py b/src/discordbot/discordbot.py index d7f93be..484561e 100644 --- a/src/discordbot/discordbot.py +++ b/src/discordbot/discordbot.py @@ -93,12 +93,17 @@ async def query_database(): global database global rechead db_url = f'https://{scheduler_hostname}/database' - if requests.get(db_url).status_code == 200: - response = requests.get(db_url) - response.raise_for_status() - database = response.json() - else: + try: + if requests.get(db_url).status_code == 200: + response = requests.get(db_url) + response.raise_for_status() + database = response.json() + else: + logger_discord.error('Cannot connect to the database!') + return + except Exception as e: logger_discord.error('Cannot connect to the database!') + logger_discord.error(e) return if database == {}: