fix(client): streaming abort error handling (#98)
This commit is contained in:
parent
31bf04596d
commit
48bb6b3a50
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@fal-ai/client",
|
"name": "@fal-ai/client",
|
||||||
"description": "The fal.ai client for JavaScript and TypeScript",
|
"description": "The fal.ai client for JavaScript and TypeScript",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export type { RealtimeClient } from "./realtime";
|
|||||||
export { ApiError, ValidationError } from "./response";
|
export { ApiError, ValidationError } from "./response";
|
||||||
export type { ResponseHandler } from "./response";
|
export type { ResponseHandler } from "./response";
|
||||||
export type { StorageClient } from "./storage";
|
export type { StorageClient } from "./storage";
|
||||||
export type { StreamingClient } from "./streaming";
|
export type { FalStream, StreamingClient } from "./streaming";
|
||||||
export * from "./types";
|
export * from "./types";
|
||||||
export type {
|
export type {
|
||||||
QueueStatus,
|
QueueStatus,
|
||||||
|
|||||||
@ -265,6 +265,13 @@ export class FalStream<Input, Output> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private handleError = (error: any) => {
|
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 =
|
const apiError =
|
||||||
error instanceof ApiError
|
error instanceof ApiError
|
||||||
? error
|
? error
|
||||||
@ -325,6 +332,15 @@ export class FalStream<Input, Output> {
|
|||||||
public abort = () => {
|
public abort = () => {
|
||||||
this.abortController.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user