File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,23 @@ def get_v1_rest_client(
5757
5858def raise_if_error (response : Response , * args : Any , ** kwargs : Any ) -> None :
5959 if response .status_code < 200 or response .status_code >= 300 :
60- error = error_adapter .validate_json (response .text )
61- response .reason = "\n " .join ([e .message for e in error .errors ])
60+ # Try to parse JSON error response first
61+ try :
62+ error = error_adapter .validate_json (response .text )
63+ response .reason = "\n " .join ([e .message for e in error .errors ])
64+ except Exception as e :
65+ # If JSON parsing fails, assume non-JSON response (likely HTML for 5XX errors)
66+ # For 5XX errors, this enables retry via HTTPError
67+ logger .warning (
68+ f"Failed to parse error response as JSON: { e } . "
69+ f"Status: { response .status_code } , URL: { response .url } , "
70+ f"Response preview: { response .text [:200 ]} ..."
71+ )
72+ if response .status_code >= 500 :
73+ response .reason = f"Server error ({ response .status_code } ): Non-JSON response received (likely HTML)"
74+ else :
75+ response .reason = f"API error ({ response .status_code } ): Unable to parse error response"
76+
6277 response .raise_for_status ()
6378
6479
You can’t perform that action at this time.
0 commit comments