From 953d978cc7e6881ae84a4b88229afca41058b30d Mon Sep 17 00:00:00 2001 From: Andrey Epifancev Date: Sat, 3 Oct 2026 22:26:18 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B8=D0=BA=20422=20=E2=80=94=20=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B0=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D1=83=D1=81=D0=B0=20=D0=B8=20=D1=81=D0=B5=D1=80=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20ctx=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Без jsonable_encoder ValueError из field_validator давал 500 вместо 422; HTTP_422_UNPROCESSABLE_ENTITY помечена устаревшей в starlette. Co-Authored-By: Claude Fable 5.1 --- api/src/core/exception_handlers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/src/core/exception_handlers.py b/api/src/core/exception_handlers.py index f7643c2..42a585b 100644 --- a/api/src/core/exception_handlers.py +++ b/api/src/core/exception_handlers.py @@ -1,4 +1,5 @@ from fastapi import FastAPI, HTTPException, Request, status +from fastapi.encoders import jsonable_encoder from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse from sqlalchemy.exc import IntegrityError, SQLAlchemyError @@ -8,8 +9,9 @@ def register_exception_handlers(app: FastAPI) -> None: @app.exception_handler(RequestValidationError) async def request_validation_exception_handler(_: Request, exc: RequestValidationError): return JSONResponse( - status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, - content={"detail": exc.errors()}, + status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, + # ctx ошибки может содержать исключение (ValueError из валидатора) — сериализуем через jsonable_encoder + content={"detail": jsonable_encoder(exc.errors())}, ) @app.exception_handler(IntegrityError)