Skip to content

Commit 1ab722e

Browse files
Move is_api_error_response out of SeamHttpClient class
1 parent 0e5aa28 commit 1ab722e

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

seam/client.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _handle_error_response(self, response: requests.Response):
6161
if status_code == 401:
6262
raise SeamHttpUnauthorizedError(request_id)
6363

64-
if not self._is_api_error_response(response):
64+
if not is_api_error_response(response):
6565
response.raise_for_status()
6666

6767
error = response.json().get("error", {})
@@ -80,30 +80,31 @@ def _handle_error_response(self, response: requests.Response):
8080

8181
raise SeamHttpApiError(error_details, status_code, request_id)
8282

83-
def _is_api_error_response(self, response: requests.Response) -> bool:
84-
try:
85-
content_type = response.headers.get("content-type", "")
8683

87-
if not isinstance(content_type, str) or not content_type.startswith(
88-
"application/json"
89-
):
90-
return False
84+
def is_api_error_response(response: requests.Response) -> bool:
85+
try:
86+
content_type = response.headers.get("content-type", "")
9187

92-
data = response.json()
93-
except (ValueError, requests.exceptions.JSONDecodeError):
88+
if not isinstance(content_type, str) or not content_type.startswith(
89+
"application/json"
90+
):
9491
return False
9592

96-
if not isinstance(data, dict):
97-
return False
93+
data = response.json()
94+
except (ValueError, requests.exceptions.JSONDecodeError):
95+
return False
9896

99-
error = data.get("error")
97+
if not isinstance(data, dict):
98+
return False
10099

101-
if not isinstance(error, dict):
102-
return False
100+
error = data.get("error")
103101

104-
if not isinstance(error.get("type"), str) or not isinstance(
105-
error.get("message"), str
106-
):
107-
return False
102+
if not isinstance(error, dict):
103+
return False
104+
105+
if not isinstance(error.get("type"), str) or not isinstance(
106+
error.get("message"), str
107+
):
108+
return False
108109

109-
return True
110+
return True

0 commit comments

Comments
 (0)