fix(client): streaming abort error handling (#98)

This commit is contained in:
Daniel Rochetti 2024-10-28 21:06:38 -07:00 committed by GitHub
parent 31bf04596d
commit 48bb6b3a50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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
@ -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;
}
}
/**