Skip to content

Handle HTTP status errors in streaming sessions #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

SplittyDev
Copy link
Contributor

@SplittyDev SplittyDev commented Mar 16, 2025

What

This PR adds proper HTTP error handling to StreamingSession, and exposes access to both the HTTPURLResponse as well as the statusCode via OpenAIError/statusError.

Why

HTTP status errors (404, 500, etc.) aren't currently handled in streaming sessions. Instead, if an error is encountered, the streaming session simply terminates without yielding any chunks, which is very much unexpected.

Affected Areas

This is simply an additional delegate method implementation on StreamingSession (urlSession(session:dataTask:didReceive:completionHandler:)), and it's mostly an internal change that's transparent to users.

Users should already be handling OpenAIError anyway, so hopefully this shouldn't cause any unexpected behavior for anyone. Personally, I would not consider this a breaking change.

@SplittyDev
Copy link
Contributor Author

Btw, as far as I can tell this is different from what's been done in #266, as this actually handles HTTP-specific errors. This is basically what I discussed in #261, which was not resolved by #266.

Copy link
Collaborator

@nezhyborets nezhyborets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@SplittyDev SplittyDev force-pushed the upstream/streaming-error-handling branch 2 times, most recently from 35b0793 to e7bf67f Compare March 21, 2025 11:44
@SplittyDev SplittyDev force-pushed the upstream/streaming-error-handling branch from e7bf67f to 3447365 Compare March 21, 2025 11:46
Copy link

@nezhyborets nezhyborets merged commit 5c647c9 into MacPaw:main Mar 21, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants