Skip to content

fix(api): return Problem Details for FastAPI request validation errors - #40

Merged
mortenoh merged 1 commit into
mainfrom
fix/request-validation-problem-details
Sep 6, 2026
Merged

mortenoh merged 1 commit into
mainfrom
fix/request-validation-problem-details

Conversation

@mortenoh

@mortenoh mortenoh commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

add_error_handlers registered a handler for pydantic.ValidationError but not for fastapi.exceptions.RequestValidationError. A malformed request body or an out-of-range query parameter (for example ?page=0 on a CRUD list route) therefore still returned FastAPI's default {"detail": [...]} body with application/json, while every other error in the API is RFC 9457 Problem Details. Found while documenting the 2.0 behavior in chapkit.

RequestValidationError now goes through the same validation_error_handler: status 422, application/problem+json, generic detail, a trace_id, and the structured error list under the errors extension member with its loc, type, and msg fields intact.

Test plan

  • New tests post an invalid body and an out-of-range query parameter to routes on the handler test app and assert the Problem Details shape, media type, and errors[0].loc of ["body", "name"] and ["query", "page"].
  • make lint clean; make test 503 passed (501 before). No existing test asserted the old plain body.

add_error_handlers registered a handler for pydantic.ValidationError
but not for fastapi.exceptions.RequestValidationError, so a malformed
request body or an out-of-range query parameter still produced FastAPI's
plain {"detail": [...]} body while every other error was RFC 9457.
Route RequestValidationError through the same handler, keeping the
structured errors list under the errors extension.
@mortenoh
mortenoh merged commit 089012d into main Sep 6, 2026
7 checks passed
@mortenoh
mortenoh deleted the fix/request-validation-problem-details branch September 6, 2026 18:13
@mortenoh mortenoh mentioned this pull request Sep 6, 2026
mortenoh added a commit that referenced this pull request Sep 6, 2026
Bump version 2.0.1 -> 2.0.2 and refresh the lockfile. Patch release
routing FastAPI request validation errors through the Problem Details
handler (#40).
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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