Skip to content
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
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 @@ -99,7 +99,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 @@ -129,6 +133,9 @@ export class FunctionsClient {

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