diff --git a/ref-test/app/api/views.py b/ref-test/app/api/views.py index 00a141f..08f6177 100644 --- a/ref-test/app/api/views.py +++ b/ref-test/app/api/views.py @@ -80,10 +80,8 @@ def _submit_quiz(): def _editor(id:str=None): request_data = request.get_json() id = request_data['id'] - try: - dataset = Dataset.query.filter_by(id=id).first() - user = User.query.filter_by(id=creator).first() - except SQLAlchemyError as exception: + try: dataset = Dataset.query.filter_by(id=id).first() + except (SQLAlchemyError, ConnectionError) 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 @@ -94,6 +92,10 @@ def _editor(id:str=None): return jsonify({'success': 'Successfully downloaded dataset', 'data': data}), 200 default = request_data['default'] creator = request_data['creator'] + try: user = User.query.filter_by(id=creator).first() + except (SQLAlchemyError, ConnectionError) as exception: + write('system.log', f'Database error when processing request \'{request.url}\': {exception}') + return abort(500) name = request_data['name'] data = request_data['data'] if not validate_json(data): return jsonify({'error': 'The data you submitted was invalid.'}), 400