More elegant error handling

This commit is contained in:
2022-06-20 11:27:05 +01:00
parent 90bc30757a
commit 49a7fb1007
3 changed files with 18 additions and 23 deletions

View File

@ -1,5 +1,6 @@
from ..forms.quiz import StartQuiz
from ..models import Entry, Test
from ..tools.forms import send_errors_to_client
from ..tools.test import redirect_if_started
from flask import abort, Blueprint, jsonify, redirect, render_template, request, session
@ -52,8 +53,7 @@ def _start():
'id': entry.id
}), 200
return jsonify({'error': 'There was an error processing the user test and/or user codes.'}), 400
errors = [*form.test_code.errors, *form.user_code.errors, *form.first_name.errors, *form.surname.errors, *form.email.errors, *form.club.errors]
return jsonify({ 'error': errors}), 400
return send_errors_to_client(form=form)
return render_template('/quiz/start_quiz.html', form = form)
@quiz.route('/quiz/')