|
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) {
|
@@ -96,7 +96,11 @@ export class FunctionsClient {
|
96 | 96 | // 3. default Content-Type header
|
97 | 97 | headers: { ..._headers, ...this.headers, ...headers },
|
98 | 98 | body,
|
| 99 | + signal, |
99 | 100 | }).catch((fetchError) => {
|
| 101 | + if (fetchError.name === 'AbortError') { |
| 102 | + throw fetchError; |
| 103 | + } |
100 | 104 | throw new FunctionsFetchError(fetchError)
|
101 | 105 | })
|
102 | 106 |
|
@@ -126,6 +130,9 @@ export class FunctionsClient {
|
126 | 130 |
|
127 | 131 | return { data, error: null }
|
128 | 132 | } catch (error) {
|
| 133 | + if (error instanceof Error && error.name === 'AbortError') { |
| 134 | + return { data: null, error: new FunctionsFetchError(error) } |
| 135 | + } |
129 | 136 | return { data: null, error }
|
130 | 137 | }
|
131 | 138 | }
|
|
0 commit comments