Generalise exception handling
This commit is contained in:
@@ -56,7 +56,7 @@ class Test(db.Model):
|
||||
try:
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
except (SQLAlchemyError, ConnectionError) as exception:
|
||||
except Exception as exception:
|
||||
db.session.rollback()
|
||||
write('system.log', f'Database error when creating test {self.get_code()}: {exception}')
|
||||
return False, f'Database error: {exception}'
|
||||
@@ -67,7 +67,7 @@ class Test(db.Model):
|
||||
if self.entries: return False, f'Cannot delete a test with submitted entries.'
|
||||
db.session.delete(self)
|
||||
try: db.session.commit()
|
||||
except (SQLAlchemyError, ConnectionError) as exception:
|
||||
except Exception as exception:
|
||||
db.session.rollback()
|
||||
write('system.log', f'Database error when deleting test {self.get_code()}: {exception}')
|
||||
return False, f'Database error: {exception}'
|
||||
@@ -79,7 +79,7 @@ class Test(db.Model):
|
||||
if self.start_date.date() > now.date():
|
||||
self.start_date = now
|
||||
try: db.session.commit()
|
||||
except (SQLAlchemyError, ConnectionError) as exception:
|
||||
except Exception as exception:
|
||||
db.session.rollback()
|
||||
write('system.log', f'Database error when launching test {self.get_code()}: {exception}')
|
||||
return False, f'Database error: {exception}'
|
||||
@@ -92,7 +92,7 @@ class Test(db.Model):
|
||||
if self.end_date >= now:
|
||||
self.end_date = now
|
||||
try: db.session.commit()
|
||||
except (SQLAlchemyError, ConnectionError) as exception:
|
||||
except Exception as exception:
|
||||
db.session.rollback()
|
||||
write('system.log', f'Database error when closing test {self.get_code()}: {exception}')
|
||||
return False, f'Database error: {exception}'
|
||||
@@ -106,7 +106,7 @@ class Test(db.Model):
|
||||
adjustments[code] = time
|
||||
self.adjustments = adjustments
|
||||
try: db.session.commit()
|
||||
except (SQLAlchemyError, ConnectionError) as exception:
|
||||
except Exception as exception:
|
||||
db.session.rollback()
|
||||
write('system.log', f'Database error when adding adjustment to test {self.get_code()}: {exception}')
|
||||
return False, f'Database error: {exception}'
|
||||
@@ -118,7 +118,7 @@ class Test(db.Model):
|
||||
self.adjustments.pop(code)
|
||||
if not self.adjustments: self.adjustments = None
|
||||
try: db.session.commit()
|
||||
except (SQLAlchemyError, ConnectionError) as exception:
|
||||
except Exception as exception:
|
||||
db.session.rollback()
|
||||
write('system.log', f'Database error when deleting adjustment from test {self.get_code()}: {exception}')
|
||||
return False, f'Database error: {exception}'
|
||||
@@ -131,7 +131,7 @@ class Test(db.Model):
|
||||
if end_date: self.end_date = end_date
|
||||
if time_limit is not None: self.time_limit = time_limit
|
||||
try: db.session.commit()
|
||||
except (SQLAlchemyError, ConnectionError) as exception:
|
||||
except Exception as exception:
|
||||
db.session.rollback()
|
||||
write('system.log', f'Database error when updating test {self.get_code()}: {exception}')
|
||||
return False, f'Database error: {exception}'
|
||||
|
Reference in New Issue
Block a user