From 70949f76c6e0b899dcacdb605465587d5a415aad Mon Sep 17 00:00:00 2001 From: jsklan Date: Fri, 8 Aug 2025 12:53:43 -0400 Subject: [PATCH] add headers to api error --- src/square/core/api_error.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/square/core/api_error.py b/src/square/core/api_error.py index 59664655..426f851e 100644 --- a/src/square/core/api_error.py +++ b/src/square/core/api_error.py @@ -17,8 +17,15 @@ class ApiError(Exception): status_code: Optional[int] body: Any errors: List[Error] - - def __init__(self, *, status_code: Optional[int] = None, body: Any = None): + headers: Optional[Dict[str, str]] + + def __init__( + self, + *, + headers: Optional[Dict[str, str]] = None, + status_code: Optional[int] = None, + body: Any = None, + ) -> None: """ Initialize an ApiError. @@ -30,6 +37,7 @@ def __init__(self, *, status_code: Optional[int] = None, body: Any = None): self.status_code = status_code self.body = body self.errors = self._parse_errors(body) + self.headers = headers super().__init__(self._build_message(message, status_code, body)) @@ -120,4 +128,4 @@ def _parse_error(self, data: Optional[Dict[str, Any]] = None) -> Error: ) def __str__(self) -> str: - return f"status_code: {self.status_code}, body: {self.body}" + return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}"