Skip to content

fix: return a friendly 422 instead of a 500 when a form fails validation - #425

Merged
jontyms merged 1 commit into
HackUCF:devfrom
jontyms:fix/form-validation-422
Sep 24, 2026
Merged

jontyms merged 1 commit into
HackUCF:devfrom
jontyms:fix/form-validation-422

Conversation

@jontyms

@jontyms jontyms commented Sep 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes GlitchTip ONBOARD-3N (7 events). post_form called model(**inp) without catching pydantic's ValidationError, so any submission that failed form validation returned a 500 and the member saw nothing useful. Two causes seen in the events:

Now it's a 422 that names the fields that failed, using the labels the member sees, which form.js shows in its error banner:

Please check: Preferred Email. If the form changed since you opened it, reload the page and try again.

  • app/util/forms.py: new form_field_labels() maps field keys to their visible label. Quiz radios use their scenario heading.
  • app/routes/api.py: catches ValidationError, logs a warning with field names and error types only (the input is PII), and raises the 422.

Testing

  • New tests cover both cases from the GlitchTip events (a stale quiz option and a malformed email).
  • pytest: 65 passed, 1 skipped. ruff and pyrefly clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VJTrZnhWMDKQ51nmshVqsJ

post_form didn't catch pydantic's ValidationError, so a malformed email
or a radio answer from a page opened before the form's options changed
crashed with a 500 and no message. Catch it and name the fields that
failed, using the labels the member sees. Log only field names and error
types, since the input is PII.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJTrZnhWMDKQ51nmshVqsJ
@jontyms
jontyms merged commit 0eb45a3 into HackUCF:dev Sep 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant