|
1 | 1 | import { resolveFetch } from './helper'
|
2 | 2 | import {
|
3 | 3 | Fetch,
|
| 4 | + FunctionInvokeOptions, |
| 5 | + FunctionRegion, |
4 | 6 | FunctionsFetchError,
|
5 | 7 | FunctionsHttpError,
|
6 | 8 | FunctionsRelayError,
|
7 | 9 | FunctionsResponse,
|
8 |
| - FunctionInvokeOptions, |
9 |
| - FunctionRegion, |
10 | 10 | } from './types'
|
11 | 11 |
|
12 | 12 | export class FunctionsClient {
|
@@ -51,7 +51,7 @@ export class FunctionsClient {
|
51 | 51 | options: FunctionInvokeOptions = {}
|
52 | 52 | ): Promise<FunctionsResponse<T>> {
|
53 | 53 | try {
|
54 |
| - const { headers, method, body: functionArgs } = options |
| 54 | + const { headers, method, body: functionArgs, signal } = options |
55 | 55 | let _headers: Record<string, string> = {}
|
56 | 56 | let { region } = options
|
57 | 57 | if (!region) {
|
@@ -99,7 +99,11 @@ export class FunctionsClient {
|
99 | 99 | // 3. default Content-Type header
|
100 | 100 | headers: { ..._headers, ...this.headers, ...headers },
|
101 | 101 | body,
|
| 102 | + signal, |
102 | 103 | }).catch((fetchError) => {
|
| 104 | + if (fetchError.name === 'AbortError') { |
| 105 | + throw fetchError; |
| 106 | + } |
103 | 107 | throw new FunctionsFetchError(fetchError)
|
104 | 108 | })
|
105 | 109 |
|
@@ -129,6 +133,9 @@ export class FunctionsClient {
|
129 | 133 |
|
130 | 134 | return { data, error: null, response }
|
131 | 135 | } catch (error) {
|
| 136 | + if (error instanceof Error && error.name === 'AbortError') { |
| 137 | + return { data: null, error: new FunctionsFetchError(error) } |
| 138 | + } |
132 | 139 | return { data: null, error, response: error instanceof FunctionsHttpError || error instanceof FunctionsRelayError ? error.context : undefined }
|
133 | 140 | }
|
134 | 141 | }
|
|
0 commit comments