Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions src/FunctionsClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { resolveFetch } from './helper'
import {
Fetch,
FunctionInvokeOptions,
FunctionRegion,
FunctionsFetchError,
FunctionsHttpError,
FunctionsRelayError,
FunctionsResponse,
FunctionInvokeOptions,
FunctionRegion,
} from './types'

export class FunctionsClient {
Expand Down Expand Up @@ -51,7 +51,7 @@ export class FunctionsClient {
options: FunctionInvokeOptions = {}
): Promise<FunctionsResponse<T>> {
try {
const { headers, method, body: functionArgs } = options
const { headers, method, body: functionArgs, signal } = options
let _headers: Record<string, string> = {}
let { region } = options
if (!region) {
Expand Down Expand Up @@ -96,7 +96,11 @@ export class FunctionsClient {
// 3. default Content-Type header
headers: { ..._headers, ...this.headers, ...headers },
body,
signal,
}).catch((fetchError) => {
if (fetchError.name === 'AbortError') {
throw fetchError;
}
throw new FunctionsFetchError(fetchError)
})

Expand Down Expand Up @@ -126,6 +130,9 @@ export class FunctionsClient {

return { data, error: null }
} catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
return { data: null, error: new FunctionsFetchError(error) }
}
return { data: null, error }
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ export type FunctionInvokeOptions = {
| ReadableStream<Uint8Array>
| Record<string, any>
| string
/**
* The AbortSignal to use for the request.
* */
signal?: AbortSignal
}