Skip to content

Commit b1fc43f

Browse files
committed
added path and orig status code to do_request exceptions
1 parent 10ac125 commit b1fc43f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

socketdev/core/api.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,25 @@ def format_headers(headers_dict):
6060
request_duration = time.time() - start_time
6161

6262
headers_str = f"\n\nHeaders:\n{format_headers(response.headers)}" if response.headers else ""
63+
path_str = f"\nPath: {url}"
6364

6465
if response.status_code == 401:
65-
raise APIAccessDenied(f"Unauthorized{headers_str}")
66+
raise APIAccessDenied(f"Unauthorized{path_str}{headers_str}")
6667
if response.status_code == 403:
6768
try:
6869
error_message = response.json().get("error", {}).get("message", "")
6970
if "Insufficient permissions for API method" in error_message:
70-
raise APIInsufficientPermissions(f"{error_message}{headers_str}")
71+
raise APIInsufficientPermissions(f"{error_message}{path_str}{headers_str}")
7172
elif "Organization not allowed" in error_message:
72-
raise APIOrganizationNotAllowed(f"{error_message}{headers_str}")
73+
raise APIOrganizationNotAllowed(f"{error_message}{path_str}{headers_str}")
7374
elif "Insufficient max quota" in error_message:
74-
raise APIInsufficientQuota(f"{error_message}{headers_str}")
75+
raise APIInsufficientQuota(f"{error_message}{path_str}{headers_str}")
7576
else:
76-
raise APIAccessDenied(f"{error_message or 'Access denied'}{headers_str}")
77+
raise APIAccessDenied(f"{error_message or 'Access denied'}{path_str}{headers_str}")
7778
except ValueError:
78-
raise APIAccessDenied(f"Access denied{headers_str}")
79+
raise APIAccessDenied(f"Access denied{path_str}{headers_str}")
7980
if response.status_code == 404:
80-
raise APIResourceNotFound(f"Path not found {path}{headers_str}")
81+
raise APIResourceNotFound(f"Path not found {path}{path_str}{headers_str}")
8182
if response.status_code == 429:
8283
retry_after = response.headers.get("retry-after")
8384
if retry_after:
@@ -90,11 +91,14 @@ def format_headers(headers_dict):
9091
time_msg = f" Retry after: {retry_after}"
9192
else:
9293
time_msg = ""
93-
raise APIInsufficientQuota(f"Insufficient quota for API route.{time_msg}{headers_str}")
94+
raise APIInsufficientQuota(f"Insufficient quota for API route.{time_msg}{path_str}{headers_str}")
9495
if response.status_code == 502:
95-
raise APIBadGateway("Upstream server error")
96+
raise APIBadGateway(f"Upstream server error{path_str}{headers_str}")
9697
if response.status_code >= 400:
97-
raise APIFailure(f"Bad Request: HTTP {response.status_code}{headers_str}")
98+
raise APIFailure(
99+
f"Bad Request: HTTP original_status_code:{response.status_code}{path_str}{headers_str}",
100+
status_code=500,
101+
)
98102

99103
return response
100104

0 commit comments

Comments
 (0)