Include connection errors in exception handling

This commit is contained in:
2022-08-20 12:58:47 +01:00
parent 168b2b288a
commit 72f2af1df8
15 changed files with 63 additions and 68 deletions

View File

@@ -74,7 +74,7 @@ class Entry(db.Model):
try:
db.session.add(self)
db.session.commit()
except SQLAlchemyError as exception:
except (SQLAlchemyError, ConnectionError) 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 as exception:
except (SQLAlchemyError, ConnectionError) 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 as exception:
except (SQLAlchemyError, ConnectionError) 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 as exception:
except (SQLAlchemyError, ConnectionError) 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 as exception:
except (SQLAlchemyError, ConnectionError) as exception:
db.session.rollback()
write('system.log', f'Database error when deleting entry {id}: {exception}')
return False, f'Database error: {exception}'
@@ -199,5 +199,4 @@ class Entry(db.Model):
"""
)
try: mail.send(email)
except SMTPException 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 (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}')