Skip to content
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

fix(client): streaming abort error handling #98

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fal-ai/client",
"description": "The fal.ai client for JavaScript and TypeScript",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion libs/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type { RealtimeClient } from "./realtime";
export { ApiError, ValidationError } from "./response";
export type { ResponseHandler } from "./response";
export type { StorageClient } from "./storage";
export type { StreamingClient } from "./streaming";
export type { FalStream, StreamingClient } from "./streaming";
export * from "./types";
export type {
QueueStatus,
Expand Down
16 changes: 16 additions & 0 deletions libs/client/src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ export class FalStream<Input, Output> {
};

private handleError = (error: any) => {
// In case AbortError is thrown but the signal is marked as aborted
// it means the user called abort() and we should not emit an error
// as it's expected behavior
// See note on: https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort
if (this.signal.aborted) {
return;
}
const apiError =
error instanceof ApiError
? error
Expand Down Expand Up @@ -325,6 +332,15 @@ export class FalStream<Input, Output> {
public abort = () => {
this.abortController.abort();
};

/**
* Gets the `AbortSignal` instance that can be used to listen for abort events.
* @returns the `AbortSignal` instance.
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
*/
public get signal() {
return this.abortController.signal;
}
}

/**
Expand Down
Loading