From df5b1a072d99ff8aee0c94304b2a0214f0fcffe7 Mon Sep 17 00:00:00 2001 From: Fringg Date: Tue, 17 Feb 2026 18:46:32 +0300 Subject: [PATCH] fix: handle YooKassa NotFoundError gracefully in get_payment_info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Catch NotFoundError (404) separately from generic exceptions. Old/expired payments return 404 from YooKassa API — this is expected and should be logged as WARNING without traceback, not ERROR. --- app/services/yookassa_service.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/services/yookassa_service.py b/app/services/yookassa_service.py index 671a5fa6..8403b89f 100644 --- a/app/services/yookassa_service.py +++ b/app/services/yookassa_service.py @@ -5,6 +5,7 @@ from typing import Any import structlog from yookassa import Configuration, Payment as YooKassaPayment from yookassa.domain.common.confirmation_type import ConfirmationType +from yookassa.domain.exceptions.not_found_error import NotFoundError as YooKassaNotFoundError from yookassa.domain.request.payment_request_builder import PaymentRequestBuilder from app.config import settings @@ -412,6 +413,12 @@ class YooKassaService: } logger.warning('Платеж не найден в YooKassa ID', payment_id_in_yookassa=payment_id_in_yookassa) return None + except YooKassaNotFoundError: + logger.warning( + 'Платеж не найден в YooKassa (404)', + payment_id_in_yookassa=payment_id_in_yookassa, + ) + return None except Exception as e: logger.error( 'Ошибка получения информации о платеже YooKassa',