-
Notifications
You must be signed in to change notification settings - Fork 22
Closed
Description
Bug
When a provider returns a non-200 HTTP response with a binary (non-UTF-8) body, _handle_error_response raises UnicodeDecodeError instead of the expected httpx.HTTPStatusError.
Root cause
In client.py, _handle_error_response:
except (JSONDecodeError, KeyError, TypeError, IndexError):
error_msg = response.text or f"HTTP {response.status_code}"response.text is httpx's UTF-8-decoded property. When the error body contains binary bytes (e.g. 0xff), it raises UnicodeDecodeError — which is not in the caught exception list — so httpx.HTTPStatusError is never raised.
Observed
ElevenLabs occasionally returns a binary error body, causing:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 45
Fix
except (JSONDecodeError, KeyError, TypeError, IndexError):
error_msg = response.content.decode("utf-8", errors="replace") or f"HTTP {response.status_code}"response.content is the raw bytes. errors="replace" substitutes U+FFFD for undecodable bytes instead of raising.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels