Repository navigation
fix(api): return Problem Details for FastAPI request validation errors - #40
Merged
Merged
Conversation
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.
Merged
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
add_error_handlersregistered a handler forpydantic.ValidationErrorbut not forfastapi.exceptions.RequestValidationError. A malformed request body or an out-of-range query parameter (for example?page=0on a CRUD list route) therefore still returned FastAPI's default{"detail": [...]}body withapplication/json, while every other error in the API is RFC 9457 Problem Details. Found while documenting the 2.0 behavior in chapkit.RequestValidationErrornow goes through the samevalidation_error_handler: status 422,application/problem+json, genericdetail, atrace_id, and the structured error list under theerrorsextension member with itsloc,type, andmsgfields intact.Test plan
errors[0].locof["body", "name"]and["query", "page"].make lintclean;make test503 passed (501 before). No existing test asserted the old plain body.