improve error handling for the case the database can not be reached
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user