improve error handling for the case the database can not be reached

This commit is contained in:
David Rodenkirchen
2024-08-29 08:56:56 +02:00
parent 2326907141
commit ec2b5f0b0d
4 changed files with 125 additions and 5 deletions
@@ -21,6 +21,9 @@ logger = logging.getLogger(__name__.split(".")[-1])
class DuplicationError(Exception):
pass
class NoDatabaseConnectionError(Exception):
pass
class DatabaseService:
def __init__(self, database_config: DatabaseConfiguration) -> None:
self._database_config = database_config
@@ -37,8 +40,8 @@ class DatabaseService:
database=self._database_config.db_name
)
except mariadb.Error as e:
logger.fatal(f"Error connecting to database: {e}")
sys.exit(1)
logger.error(f"Error connecting to database: {e}")
raise NoDatabaseConnectionError
def _get_cursor(self) -> Cursor:
return self._connection.cursor()