Skip to content

Commit f12e7c8

Browse files
committed
Add timeout constant and bring back minimum timeout value
1 parent e9ae353 commit f12e7c8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/vertexai/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ export const DEFAULT_API_VERSION = 'v1beta';
2828
export const PACKAGE_VERSION = version;
2929

3030
export const LANGUAGE_TAG = 'gl-js';
31+
32+
export const DEFAULT_FETCH_TIMEOUT_MS = 180 * 1000;

packages/vertexai/src/requests/request.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ApiSettings } from '../types/internal';
2121
import {
2222
DEFAULT_API_VERSION,
2323
DEFAULT_BASE_URL,
24+
DEFAULT_FETCH_TIMEOUT_MS,
2425
LANGUAGE_TAG,
2526
PACKAGE_VERSION
2627
} from '../constants';
@@ -145,9 +146,9 @@ export async function makeRequest(
145146
);
146147
// Timeout is 180s by default
147148
const timeoutMillis =
148-
requestOptions?.timeout !== undefined
149+
requestOptions?.timeout !== undefined && requestOptions.timeout >= 0
149150
? requestOptions.timeout
150-
: 180 * 1000;
151+
: DEFAULT_FETCH_TIMEOUT_MS;
151152
const abortController = new AbortController();
152153
fetchTimeoutId = setTimeout(() => abortController.abort(), timeoutMillis);
153154
request.fetchOptions.signal = abortController.signal;

0 commit comments

Comments
 (0)