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, )