Skip to content

Commit

Permalink
fix(stream-text): incorrectly handled errors (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: iseki <admin@iseki.space>
  • Loading branch information
nekomeowww and iseki0 authored Jan 18, 2025
1 parent 90d0db0 commit 34970df
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/stream-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export const streamText = async (options: StreamTextOptions): Promise<StreamText
continue
}

if (line.startsWith(chunkErrorPrefix)) {
const lineWithoutPrefix = line.slice(chunkHeaderPrefix.length)
if (lineWithoutPrefix.startsWith(chunkErrorPrefix)) {
// About controller error: https://developer.mozilla.org/en-US/docs/Web/API/TransformStreamDefaultController/error
controller.error(new Error(`Error from server: ${line}`))
controller.error(new Error(`Error from server: ${lineWithoutPrefix}`))
break
}

const lineWithoutPrefix = line.slice(chunkHeaderPrefix.length)
if (lineWithoutPrefix === '[DONE]') {
controller.terminate()
break
Expand Down

0 comments on commit 34970df

Please sign in to comment.