Skip to content

Commit

Permalink
chore: make sure rejects return errors, not string (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp authored Sep 30, 2024
1 parent 575359b commit b35952c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/olive-yaks-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@livekit/agents": patch
"@livekit/agents-plugin-openai": patch
---

make sure rejects return errors, not string
2 changes: 1 addition & 1 deletion agents/src/multimodal/multimodal_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class MultimodalAgent {
): Promise<RealtimeSession> {
return new Promise(async (resolve, reject) => {
if (this.#started) {
reject('MultimodalAgent already started');
reject(new Error('MultimodalAgent already started'));
}
this.#updateState();

Expand Down
2 changes: 1 addition & 1 deletion agents/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class Worker {
await new Promise((resolve, reject) => {
this.#session!.on('open', resolve);
this.#session!.on('error', (error) => reject(error));
this.#session!.on('close', (code) => reject(`WebSocket returned ${code}`));
this.#session!.on('close', (code) => reject(new Error(`WebSocket returned ${code}`)));
});

retries = 0;
Expand Down
4 changes: 2 additions & 2 deletions plugins/openai/src/realtime/realtime_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class RealtimeSession extends multimodal.RealtimeSession {
});

this.#ws.onerror = (error) => {
reject(error.message);
reject(error);
};

await once(this.#ws, 'open');
Expand Down Expand Up @@ -576,7 +576,7 @@ export class RealtimeSession extends multimodal.RealtimeSession {
this.#closing = true;
}
if (!this.#closing) {
reject('OpenAI Realtime connection closed unexpectedly');
reject(new Error('OpenAI Realtime connection closed unexpectedly'));
}
this.#ws = null;
resolve();
Expand Down

0 comments on commit b35952c

Please sign in to comment.