fix cdek client

This commit is contained in:
Раис Юсупалиев
2026-03-08 23:35:04 +03:00
parent f799f2ba03
commit 2d68aff34d
7 changed files with 105 additions and 8 deletions
+18 -1
View File
@@ -6,7 +6,7 @@ import json
from collections.abc import Callable, Iterable, Sequence
from typing import Protocol
from app.adapters.delivery_providers.base import DeliveryProvider
from app.adapters.delivery_providers.base import DeliveryProvider, ProviderRequestError
from app.domain.price import (
DEFAULT_WEIGHT_ROUND_SCALE,
NormalizedDeliveryRequest,
@@ -21,6 +21,10 @@ class AggregatorServiceError(RuntimeError):
"""Base exception for AggregatorService failures."""
class InvalidDeliveryRequestError(AggregatorServiceError):
"""Raised when provider rejects delivery request as invalid."""
class PriceCacheProtocol(Protocol):
async def get(self, key: str) -> object | None: ...
@@ -69,6 +73,19 @@ class AggregatorService:
for price in provider_results
if isinstance(price, DeliveryPrice)
]
provider_errors = [
error
for error in provider_results
if isinstance(error, Exception)
]
if (
not successful_results
and provider_errors
and any(isinstance(error, ProviderRequestError) for error in provider_errors)
):
raise InvalidDeliveryRequestError(
"Delivery request is invalid for configured providers."
)
filtered_and_sorted = self._filter_and_sort_prices(successful_results)
return [self._coerce_delivery_price(price) for price in filtered_and_sorted]