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

@ -20,7 +20,7 @@ api = Blueprint(
def _fetch_questions():
id = request.get_json()['id']
try: entry = Entry.query.filter_by(id=id).first()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
return abort(500)
if not entry: return jsonify({'error': 'Invalid entry ID.'}), 400
@ -57,7 +57,7 @@ def _submit_quiz():
id = request.get_json()['id']
answers = request.get_json()['answers']
try: entry = Entry.query.filter_by(id=id).first()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
return abort(500)
if not entry: return jsonify({'error': 'Unrecognised Entry.'}), 400
@ -81,7 +81,7 @@ def _editor(id:str=None):
request_data = request.get_json()
id = request_data['id']
try: dataset = Dataset.query.filter_by(id=id).first()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
return abort(500)
if not dataset: return jsonify({'error': 'Invalid request. Dataset not found.'}), 404
@ -93,7 +93,7 @@ def _editor(id:str=None):
default = request_data['default']
creator = request_data['creator']
try: user = User.query.filter_by(id=creator).first()
except (SQLAlchemyError, ConnectionError) as exception:
except Exception as exception:
write('system.log', f'Database error when processing request \'{request.url}\': {exception}')
return abort(500)
name = request_data['name']