Surface streaming HTTP errors at the function call instead of as first stream item#558
Merged
Merged
Conversation
… first stream item
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.
Surfaces non-2xx HTTP responses as
Err(OpenAIError::ApiError(_))from the streaming methods (post_stream,post_stream_mapped_raw_events,get_stream) instead of delivering them as the first item of the returned stream. Centralizes the status check inexecute_responseso all callers (unary and streaming) share one code path for "non-2xx → error."Closes #553.
Changes
execute_responsenow bails withread_error_response(response).awaiton non-success status, so every downstream caller sees only 2xx responses.read_error_responsehelper consumes a non-2xx response and produces the matchingOpenAIError::ApiError(ApiErrorResponse { .. }). It's the single source of truth for HTTP error construction — previously this logic was duplicated inline inread_responseand (incorrectly, via anInvalidArgumentfallback) in the wasmstream_mapped_raw_events.read_response,execute_stream,execute_stream_mapped_raw_events, and bothstream_mapped_raw_eventsimpls drop their now-redundant local status checks.OpenAIError::InvalidArgument(...)fallback from the wasm streaming path (per maintainer feedback on Title: create_stream* methods return Ok(stream) on HTTP error; error surfaces as first stream item instead of as Err from the call #553 —InvalidArgumentis reserved for client-side validation).