Skip to content

fix: add helpful error messages for URL validation#943

Merged
maxachis merged 1 commit intoPolice-Data-Accessibility-Project:devfrom
labradorite-dev:mc_906_url_validation_errors
Feb 10, 2026
Merged

fix: add helpful error messages for URL validation#943
maxachis merged 1 commit intoPolice-Data-Accessibility-Project:devfrom
labradorite-dev:mc_906_url_validation_errors

Conversation

@labradorite-dev
Copy link
Copy Markdown
Contributor

Fixes #906

Returns proper HTTP status codes with clear error messages for:

  • URLs with fragments (#) → 400 Bad Request
  • Duplicate URL/record_type combinations → 409 Conflict

Previously returned generic 500 errors.

All tests passing (9/9).

- Add Pydantic field validator to reject URLs with fragments (#)
- Handle IntegrityError to distinguish between constraint violations
- Return 400 Bad Request for URLs with fragments
- Return 409 Conflict for duplicate URL/record_type combinations
- Add Pydantic ValidationError handling in request middleware
- Add comprehensive integration tests for error cases

Database check constraints (23514) and unique constraints (23505) are
now caught and converted to user-friendly error messages instead of
generic 500 errors.

All tests passing (9/9 data source integration tests).

Fixes Police-Data-Accessibility-Project#906
@josh-chamberlain josh-chamberlain requested review from maxachis and removed request for josh-chamberlain February 10, 2026 16:39
@josh-chamberlain
Copy link
Copy Markdown
Contributor

@labradorite-dev hey, thanks for the contribution and sorry about my delay! I asked someone else to take a look at it, and update the CODEOWNERS to be more helpful in the future. He might make some stylistic suggestions, but we appreciate you following the instructions and making a useful contribution.

@maxachis maxachis merged commit b1a4fb9 into Police-Data-Accessibility-Project:dev Feb 10, 2026
4 of 5 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.

3 participants