From 197c2e0bff14bd930c1f4cd3466a7d9620ec6a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Mon, 3 Nov 2025 09:17:50 -0300 Subject: [PATCH] [IMP] fastapi: show message for AccessError | MissingError --- fastapi/error_handlers.py | 4 ++-- fastapi/tests/test_fastapi.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fastapi/error_handlers.py b/fastapi/error_handlers.py index 192ef4064..0c67a52e9 100644 --- a/fastapi/error_handlers.py +++ b/fastapi/error_handlers.py @@ -36,10 +36,10 @@ def convert_exception_to_status_body(exc: Exception) -> tuple[int, dict]: details = jsonable_encoder(exc.errors()) elif isinstance(exc, AccessDenied | AccessError): status_code = status.HTTP_403_FORBIDDEN - details = "AccessError" + details = exc.args[0] elif isinstance(exc, MissingError): status_code = status.HTTP_404_NOT_FOUND - details = "MissingError" + details = exc.args[0] elif isinstance(exc, UserError): status_code = status.HTTP_400_BAD_REQUEST details = exc.args[0] diff --git a/fastapi/tests/test_fastapi.py b/fastapi/tests/test_fastapi.py index c9eae09b8..04ef493cc 100644 --- a/fastapi/tests/test_fastapi.py +++ b/fastapi/tests/test_fastapi.py @@ -130,7 +130,7 @@ def test_access_error(self) -> None: self.assert_exception_processed( exception_type=DemoExceptionType.access_error, error_message="test", - expected_message="AccessError", + expected_message="test", expected_status_code=status.HTTP_403_FORBIDDEN, ) @@ -138,7 +138,7 @@ def test_missing_error(self) -> None: self.assert_exception_processed( exception_type=DemoExceptionType.missing_error, error_message="test", - expected_message="MissingError", + expected_message="test", expected_status_code=status.HTTP_404_NOT_FOUND, )