refactor(api): unify typed error contract across draft pricing and publish flows

standardize typed error responses across draft, pricing and publish endpoints

reduce contract drift between related flows
keep client-side handling more predictable and consistent
This commit is contained in:
greebo
2026-03-19 19:54:42 +03:00
parent 64ec1c5180
commit af175d88dd
7 changed files with 89 additions and 38 deletions

View File

@@ -30,6 +30,7 @@ from app.schemas.pricing import (
PricingCategoryUpdateResponse,
)
from app.security.auth import require_api_key
from app.services.api_errors import raise_unprocessable
from app.services.draft_guard import validate_expected_draft_version_if_provided
router = APIRouter()
@@ -213,9 +214,10 @@ async def create_price_rule_endpoint(
try:
amount = Decimal(payload.amount)
except Exception:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Некорректная сумма",
raise_unprocessable(
code="invalid_amount",
message="Некорректная сумма",
amount=payload.amount,
)
price_rule_id = await create_price_rule(
@@ -273,9 +275,10 @@ async def update_price_rule_endpoint(
try:
amount = Decimal(payload.amount)
except Exception:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Некорректная сумма",
raise_unprocessable(
code="invalid_amount",
message="Некорректная сумма",
amount=payload.amount,
)
row = await update_price_rule(