From cee86546f2519d77c429acc8311f4cd4bc8f0d3c Mon Sep 17 00:00:00 2001 From: dhoko Date: Thu, 18 Dec 2025 16:36:34 +0100 Subject: [PATCH] Log source headers inside APIException Easier to debug `ValidationError` from the server as they do not provide enough details --- crowdin_api/exceptions.py | 2 ++ crowdin_api/requester.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crowdin_api/exceptions.py b/crowdin_api/exceptions.py index 7dc8756..64d0dc2 100644 --- a/crowdin_api/exceptions.py +++ b/crowdin_api/exceptions.py @@ -34,11 +34,13 @@ def __init__( context=None, http_status=None, headers=None, + source_headers=None, should_retry=None, ): super().__init__(detail=detail) self.context = context self.headers = headers or {} + self.source_headers = source_headers or {} self.http_status = http_status or self.default_http_status if should_retry is None: diff --git a/crowdin_api/requester.py b/crowdin_api/requester.py index 24a933c..d32b4f1 100644 --- a/crowdin_api/requester.py +++ b/crowdin_api/requester.py @@ -130,18 +130,17 @@ def _request( status_code = result.status_code content = result.content - headers = result.headers # Success if status_code < 200 or status_code > 299: raise self.exception_map.get(status_code, self.default_exception)( - http_status=status_code, context=content, headers=headers + http_status=status_code, context=content, headers=result.headers, source_headers=headers ) try: return loads(content) if content else None except json.decoder.JSONDecodeError: - raise ParsingError(context=content, http_status=status_code, headers=headers) + raise ParsingError(context=content, http_status=status_code, headers=result.headers) def request( self,