Skip to content

Commit 723fe6a

Browse files
committed
fix: improve error handling for HTTP responses in QueryClient
## Summary This commit enhances the error handling mechanism in the `QueryClient` class to better manage HTTP error responses (4xx/5xx). It provides clearer error messages by parsing the response content and extracting relevant details. ## Key Changes - Added logic to handle error responses where the parsed response is `None`. - Improved exception messages to include HTTP status codes and detailed error information from the response body. ## Testing Notes - Verify that the error handling works correctly for various HTTP error scenarios. - Ensure that the exceptions raised provide meaningful information for debugging. ## Infrastructure Considerations This change improves the robustness of the `QueryClient` by ensuring that errors are reported with more context, aiding in troubleshooting and enhancing overall reliability.
1 parent 38c2727 commit 723fe6a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎robosystems_client/extensions/query_client.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,23 @@ def execute_query(
266266
else:
267267
raise Exception(f"Query execution failed: {error_msg}")
268268

269+
# Handle error responses (4xx/5xx) where parsed is None
270+
if hasattr(response, "status_code") and response.status_code >= 400:
271+
import json as _json
272+
273+
detail = f"HTTP {response.status_code}"
274+
try:
275+
body = (
276+
response.content.decode("utf-8")
277+
if isinstance(response.content, bytes)
278+
else str(response.content)
279+
)
280+
error_data = _json.loads(body)
281+
detail = error_data.get("detail", error_data.get("message", body))
282+
except Exception:
283+
pass
284+
raise Exception(f"Query failed ({response.status_code}): {detail}")
285+
269286
# Unexpected response format
270287
raise Exception("Unexpected response format from query endpoint")
271288

0 commit comments

Comments
 (0)