forked from sh-edraft.de/sh_discord_bot
Added error handling to DBContext
This commit is contained in:
parent
4bcab95369
commit
a3512b56d7
@ -6,9 +6,9 @@ from cpl_core.logging import LoggerABC
|
||||
class DBContext(DatabaseContext):
|
||||
|
||||
def __init__(self, logger: LoggerABC):
|
||||
|
||||
|
||||
self._logger = logger
|
||||
|
||||
|
||||
DatabaseContext.__init__(self)
|
||||
|
||||
def connect(self, database_settings: DatabaseSettings):
|
||||
@ -20,7 +20,7 @@ class DBContext(DatabaseContext):
|
||||
self._logger.info(__name__, "Connected to database")
|
||||
except Exception as e:
|
||||
self._logger.fatal(__name__, "Connecting to database failed", e)
|
||||
|
||||
|
||||
def save_changes(self):
|
||||
try:
|
||||
self._logger.trace(__name__, "Save changes")
|
||||
@ -28,6 +28,10 @@ class DBContext(DatabaseContext):
|
||||
self._logger.debug(__name__, "Saved changes")
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "Saving changes failed", e)
|
||||
|
||||
|
||||
def select(self, statement: str) -> list[tuple]:
|
||||
return super(DBContext, self).select(statement)
|
||||
try:
|
||||
return super(DBContext, self).select(statement)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Database error caused by {statement}', e)
|
||||
return []
|
||||
|
Loading…
Reference in New Issue
Block a user