Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion fastapi/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def convert_exception_to_status_body(exc: Exception) -> tuple[int, dict]:
status_code = exc.status_code
details = exc.detail
elif isinstance(exc, RequestValidationError):
status_code = status.HTTP_422_UNPROCESSABLE_CONTENT
# Use integer status code to supress starlette >= 0.48 deprecation warning
# See: https://github.com/fastapi/fastapi/pull/14077
# status_code = status.HTTP_422_UNPROCESSABLE_CONTENT
status_code = 422
details = jsonable_encoder(exc.errors())
elif isinstance(exc, WebSocketRequestValidationError):
status_code = status.WS_1008_POLICY_VIOLATION
Expand Down
4 changes: 1 addition & 3 deletions fastapi/tests/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ def test_request_validation_error(self) -> None:
route = "/fastapi_demo/demo/exception?exception_type=BAD&error_message="
response = self.url_open(route, timeout=200)
mocked_commit.assert_not_called()
self.assertEqual(
response.status_code, status.HTTP_422_UNPROCESSABLE_CONTENT
)
self.assertEqual(response.status_code, 422)

def test_no_commit_on_exception(self) -> None:
# this test check that the way we mock the cursor is working as expected
Expand Down