@@ -60,24 +60,25 @@ def format_headers(headers_dict):
60
60
request_duration = time .time () - start_time
61
61
62
62
headers_str = f"\n \n Headers:\n { format_headers (response .headers )} " if response .headers else ""
63
+ path_str = f"\n Path: { url } "
63
64
64
65
if response .status_code == 401 :
65
- raise APIAccessDenied (f"Unauthorized{ headers_str } " )
66
+ raise APIAccessDenied (f"Unauthorized{ path_str } { headers_str } " )
66
67
if response .status_code == 403 :
67
68
try :
68
69
error_message = response .json ().get ("error" , {}).get ("message" , "" )
69
70
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 } " )
71
72
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 } " )
73
74
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 } " )
75
76
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 } " )
77
78
except ValueError :
78
- raise APIAccessDenied (f"Access denied{ headers_str } " )
79
+ raise APIAccessDenied (f"Access denied{ path_str } { headers_str } " )
79
80
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 } " )
81
82
if response .status_code == 429 :
82
83
retry_after = response .headers .get ("retry-after" )
83
84
if retry_after :
@@ -90,11 +91,14 @@ def format_headers(headers_dict):
90
91
time_msg = f" Retry after: { retry_after } "
91
92
else :
92
93
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 } " )
94
95
if response .status_code == 502 :
95
- raise APIBadGateway ("Upstream server error" )
96
+ raise APIBadGateway (f "Upstream server error{ path_str } { headers_str } " )
96
97
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
+ )
98
102
99
103
return response
100
104
0 commit comments