-
Notifications
You must be signed in to change notification settings - Fork 398
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
Streaming does not honor http status codes #261
Comments
@SplittyDev here @eskimo (who's a famous DTS) shows his example on how to detect codes. His implementation looks similar, so I think what you did is good. As for error... I don't have a guideline on how to approach this. Gut feeling says we shouldn't bloat kinds of errors. The list should be concise, clear and informative. I think I would add a case to
This As for this concern
Let's look at it as errors in |
The only thing I'd mention is if we introduce this change, we should introduce it for regular requests also, so that regular and streaming behave the same in sense of handling status codes |
I'm a different eskimo, sorry :) |
Describe the bug
When streaming responses (e.g.
client.chatsStream(query:)
), the stream does not throw when encountering an HTTP error response. That is not only counterintuitive, but also catastrophically wrong.It breaks the expectation that errors on the server end will cause the stream to throw, makes errors undetectable and client-side error handling impossible, as any
for let result in await client.chatsStream(...)
loops just silently break, indicating that everything went well.To Reproduce
Stream a response from a server that returns an http error, for example
500
.Here's a short snippet that exhibits this issue:
In the case that the server responds with an HTTP error, the "Error" message will never be printed. Instead, you will just see the "Finished without error" message.
Expected behavior
The
AsyncThrowingStream
should throw.Additional context
I have a possible fix, but I'm not sure I like it very much:
I've extended
StreamingError
too:This works and causes the stream to throw when trying to await the first chunk, but it does not disclose the error properly, because
StreamingError
isprivate
.I see the following options:
StreamingError
public
OpenAIError
, although it's not really an OpenAI-specific errorAPIError
? But that seems to make even less sense.I also want to stress that I'm not sure that this is the best option in general. Maybe there's a much better way to detect and handle HTTP status errors. These findings are the result of a 20-minute investigation into why HTTP status errors fail to throw, and there might be a better way.
The text was updated successfully, but these errors were encountered: