Generalise exception handling

This commit is contained in:
2022-08-20 14:47:46 +01:00
parent d9837246de
commit bcee2eedd0
15 changed files with 65 additions and 65 deletions

View File

@@ -74,7 +74,7 @@ class Entry(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 preparing new entry for {self.get_surname()}, {self.get_first_name()}: {exception}')
return False, f'Database error: {exception}'
@@ -85,7 +85,7 @@ class Entry(db.Model):
self.start_time = datetime.now()
self.status = 'started'
try: db.session.commit()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
db.session.rollback()
write('system.log', f'Database error when starting test for {self.get_surname()}, {self.get_first_name()}: {exception}')
return False, f'Database error: {exception}'
@@ -104,7 +104,7 @@ class Entry(db.Model):
self.status = 'late'
self.valid = False
try: db.session.commit()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
db.session.rollback()
write('system.log', f'Database error when submitting entry for {self.get_surname()}, {self.get_first_name()}: {exception}')
return False, f'Database error: {exception}'
@@ -117,7 +117,7 @@ class Entry(db.Model):
self.valid = True
self.status = 'completed'
try: db.session.commit()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
db.session.rollback()
write('system.log', f'Database error when validating entry {self.id}: {exception}')
return False, f'Database error: {exception}'
@@ -130,7 +130,7 @@ class Entry(db.Model):
try:
db.session.delete(self)
db.session.commit()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
db.session.rollback()
write('system.log', f'Database error when deleting entry {id}: {exception}')
return False, f'Database error: {exception}'
@@ -199,4 +199,4 @@ class Entry(db.Model):
"""
)
try: mail.send(email)
except (SMTPException, ConnectionError) as exception: write('system.log', f'SMTP Error when trying to notify results to {self.get_surname()}, {self.get_first_name()} with error: {exception}')
except Exception as exception: write('system.log', f'SMTP Error when trying to notify results to {self.get_surname()}, {self.get_first_name()} with error: {exception}')