From 99a2b4278b70ec47510c8ff4bd5706826ee96163 Mon Sep 17 00:00:00 2001 From: Nikita Melkozerov Date: Wed, 28 Aug 2024 16:19:48 +0200 Subject: [PATCH] Replace message with detail in error JSON (#603) --- fixbackend/app.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fixbackend/app.py b/fixbackend/app.py index 088c27a9..2793c54c 100644 --- a/fixbackend/app.py +++ b/fixbackend/app.py @@ -180,23 +180,23 @@ async def add_logging_context(request: Request, call_next: Callable[[Request], A @app.exception_handler(NotAllowed) async def access_denied_handler(_: Request, exception: NotAllowed) -> Response: - return JSONResponse(status_code=403, content={"message": str(exception)}) + return JSONResponse(status_code=403, content={"detail": str(exception)}) @app.exception_handler(ResourceNotFound) async def resource_not_found_handler(_: Request, exception: ResourceNotFound) -> Response: - return JSONResponse(status_code=404, content={"message": str(exception)}) + return JSONResponse(status_code=404, content={"detail": str(exception)}) @app.exception_handler(InventoryException) async def inventory_exception_handler(_: Request, exception: InventoryException) -> Response: - return JSONResponse(status_code=exception.status, content={"message": str(exception)}) + return JSONResponse(status_code=exception.status, content={"detail": str(exception)}) @app.exception_handler(WrongState) async def wrong_state_handler(_: Request, exception: WrongState) -> Response: - return JSONResponse(status_code=409, content={"message": str(exception)}) + return JSONResponse(status_code=409, content={"detail": str(exception)}) @app.exception_handler(ClientError) async def client_error_handler(_: Request, exception: ClientError) -> Response: - return JSONResponse(status_code=400, content={"message": str(exception)}) + return JSONResponse(status_code=400, content={"detail": str(exception)}) @app.exception_handler(AssertionError) async def invalid_data(_: Request, exception: AssertionError) -> Response: @@ -204,7 +204,7 @@ async def invalid_data(_: Request, exception: AssertionError) -> Response: @app.exception_handler(FastAPIUsersException) async def fastapi_users_handler(_: Request, exception: FastAPIUsersException) -> Response: - return JSONResponse(status_code=400, content={"message": "invalid user"}) + return JSONResponse(status_code=400, content={"detail": "invalid user"}) class EndpointFilter(logging.Filter): endpoints_to_filter: ClassVar[Set[str]] = {