mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-12 03:16:19 +00:00
Let an error body that is an array still be read
Google answers some failures with a JSON array holding the object every other provider sends on its own. _extract_error called .get() on it and raised AttributeError, which is not the ApiError every caller is holding, so a 503 from Google took the whole dictation down instead of pasting the raw transcript with the failure shown beside it. Found by dictating against a Google AI Studio outage: HTTP Error 503: Service Unavailable AttributeError: 'list' object has no attribute 'get' It runs while an exception is being raised, so it now ends in a string whatever arrives. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -262,10 +262,23 @@ def _request(url, data, headers, timeout=120, aborter=None):
|
||||
|
||||
|
||||
def _extract_error(body):
|
||||
"""The line worth showing out of a failed request's body.
|
||||
|
||||
Whatever comes back, this has to end in a string: it is called while an
|
||||
ApiError is being raised, and an exception thrown here would escape the
|
||||
`except ApiError` every caller is holding and lose the dictation the raw
|
||||
transcript would otherwise have been pasted from.
|
||||
"""
|
||||
try:
|
||||
payload = json.loads(body)
|
||||
except json.JSONDecodeError:
|
||||
return body[:300]
|
||||
if isinstance(payload, list):
|
||||
# Google answers some failures with an array holding the object the
|
||||
# other providers send on its own.
|
||||
payload = next((item for item in payload if isinstance(item, dict)), None)
|
||||
if not isinstance(payload, dict):
|
||||
return body[:300]
|
||||
err = payload.get("error")
|
||||
if isinstance(err, dict):
|
||||
return err.get("message") or json.dumps(err)[:300]
|
||||
|
||||
Reference in New Issue
Block a user