Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/square/core/api_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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))

Expand Down Expand Up @@ -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}"
Loading