Skip to content

Commit

Permalink
chore: fix streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Jan 13, 2025
1 parent dd4af93 commit 379c743
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,12 @@ export class Stream<Item> implements AsyncIterable<Item> {
if (data && data.error) {
throw new APIError(undefined, data.error, undefined, undefined);
}

yield data;
} else {
let data;
try {
data = JSON.parse(sse.data);
} catch (e) {
console.error(`Could not parse message into JSON:`, sse.data);
console.error(`From chunk:`, sse.raw);
throw e;
}
// TODO: Is this where the error should be thrown?
if (sse.event == 'error') {
throw new APIError(undefined, data.error, data.message, undefined);
}
yield { event: sse.event, data: data } as any;

yield data;
}
}
done = true;
Expand Down

0 comments on commit 379c743

Please sign in to comment.