OracleDB: add exit_on_error parameter to connect method
This commit is contained in:
parent
d15c4f36fb
commit
8e4864f2d5
1 changed files with 18 additions and 3 deletions
|
@ -23,6 +23,18 @@ class OracleDBException(Exception):
|
|||
super().__init__(error.format(*args, **kwargs))
|
||||
|
||||
|
||||
class OracleDBFailToConnect(OracleDBException, RuntimeError):
|
||||
"""
|
||||
Raised on connecting error occurred
|
||||
"""
|
||||
|
||||
def __init__(self, dsn, user):
|
||||
super().__init__(
|
||||
"An error occured during Oracle database connection ({user}@{dsn})",
|
||||
user=user, dsn=dsn
|
||||
)
|
||||
|
||||
|
||||
class OracleDBDuplicatedSQLParameter(OracleDBException, KeyError):
|
||||
"""
|
||||
Raised when trying to set a SQL query parameter
|
||||
|
@ -72,7 +84,7 @@ class OracleDB:
|
|||
self._conn = None
|
||||
self.just_try = just_try
|
||||
|
||||
def connect(self):
|
||||
def connect(self, exit_on_error=True):
|
||||
""" Connect to Oracle server """
|
||||
if self._conn is None:
|
||||
log.info('Connect on Oracle server with DSN %s as %s', self._dsn, self._user)
|
||||
|
@ -82,12 +94,15 @@ class OracleDB:
|
|||
password=self._pwd,
|
||||
dsn=self._dsn
|
||||
)
|
||||
except Exception:
|
||||
except Exception as err:
|
||||
log.fatal(
|
||||
'An error occured during Oracle database connection (%s@%s).',
|
||||
self._user, self._dsn, exc_info=1
|
||||
)
|
||||
if exit_on_error:
|
||||
sys.exit(1)
|
||||
else:
|
||||
raise OracleDBFailToConnect(self._dsn, self._user) from err
|
||||
return True
|
||||
|
||||
def close(self):
|
||||
|
|
Loading…
Reference in a new issue