mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-09 06:15:41 -05:00
fix: defensive error body extraction to handle None and non-dict cases
Addresses review feedback: body.get('error', {}).get('message') is unsafe
when body['error'] is None or not a dict. Now properly checks isinstance()
before accessing nested fields, and falls back to top-level message field.
This commit is contained in:
@@ -1119,10 +1119,12 @@ async def _stream_chat_chunks(
|
||||
error_details = _extract_api_error_details(e)
|
||||
if error_details.get("response_body"):
|
||||
body = error_details["response_body"]
|
||||
if isinstance(body, dict) and body.get("error", {}).get(
|
||||
"message"
|
||||
):
|
||||
error_text = body["error"]["message"]
|
||||
if isinstance(body, dict):
|
||||
err = body.get("error")
|
||||
if isinstance(err, dict) and err.get("message"):
|
||||
error_text = err["message"]
|
||||
elif body.get("message"):
|
||||
error_text = body["message"]
|
||||
|
||||
if _is_region_blocked_error(e):
|
||||
error_code = "MODEL_NOT_AVAILABLE_REGION"
|
||||
|
||||
Reference in New Issue
Block a user