Don't stream events if the API returned a 4xx code

This commit is contained in:
valadaptive
2023-12-07 11:02:39 -05:00
parent 5540c165cf
commit cdcd913805
4 changed files with 55 additions and 4 deletions

View File

@ -1565,6 +1565,11 @@ async function sendOpenAIRequest(type, messages, signal) {
signal: signal,
});
if (!response.ok) {
tryParseStreamingError(response, await response.body.text());
throw new Error(`Got response status ${response.status}`);
}
if (stream) {
const eventStream = new EventSourceStream();
response.body.pipeThrough(eventStream);