diff options
author | 2020-12-10 14:52:55 +0200 | |
---|---|---|
committer | 2020-12-10 14:52:55 +0200 | |
commit | 362c665b42101762a6d55691a670ca17524a85e9 (patch) | |
tree | a7649a765812096a21a87b8089f5977517c80a43 /backend/routes/forms/submit.py | |
parent | Add validation level for same ID forms (diff) |
Make JSON errors more JS friendly and add response codes
Co-authored-by: Joe Banks <[email protected]>
Diffstat (limited to 'backend/routes/forms/submit.py')
-rw-r--r-- | backend/routes/forms/submit.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/backend/routes/forms/submit.py b/backend/routes/forms/submit.py index 054aecb..3ecbda0 100644 --- a/backend/routes/forms/submit.py +++ b/backend/routes/forms/submit.py @@ -79,12 +79,12 @@ class SubmitForm(Route): if FormFeatures.COLLECT_EMAIL.value in form.features and "email" not in response["user"]: # noqa return JSONResponse({ - "error": "User data doesn't include email." - }) + "error": "email_required" + }, status_code=400) else: return JSONResponse({ - "error": "Missing Discord user data" - }) + "error": "missing_discord_data" + }, status_code=400) missing_fields = [] for question in form.questions: @@ -93,8 +93,9 @@ class SubmitForm(Route): if missing_fields: return JSONResponse({ - "error": f"Following missing fields: {', '.join(missing_fields)}." - }) + "error": "missing_fields", + "fields": missing_fields + }, status_code=400) try: response_obj = FormResponse(**response) |