fix: enrich streaming HTTP errors with provider-specific messages#196
Merged
Kamilbenkirane merged 1 commit intomainfrom Feb 26, 2026
Merged
fix: enrich streaming HTTP errors with provider-specific messages#196Kamilbenkirane merged 1 commit intomainfrom
Kamilbenkirane merged 1 commit intomainfrom
Conversation
Streaming errors now produce the same enriched messages as non-streaming errors (e.g. "Anthropic API error: Invalid API Key" instead of the generic "Client error '401 Unauthorized' for url '...'"). Three-layer fix: - http.py: read response body before raise_for_status() so JSON error details are available downstream - streaming.py: add enrich_stream_errors() wrapper that catches HTTPStatusError and delegates to provider error handler - client.py: wire wrapper into _stream() covering all providers Closes #194
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Streaming and non-streaming HTTP errors produce inconsistent error messages:
After this PR
Both paths produce the same enriched message:
Changes
http.py: Read response body beforeraise_for_status()instream_post()andstream_post_ndjson()so JSON error details are available downstreamstreaming.py: Addenrich_stream_errors()wrapper that catchesHTTPStatusErrorand delegates to the provider's error handlerclient.py: Wire wrapper intoModalityClient._stream()— covers all providers automaticallyCloses #194
Test plan
stream_post/stream_post_ndjsonHTTP error body readabilityenrich_stream_errors(enrichment, passthrough, non-JSON body fallback)