Skip to content

Commit 96e6206

Browse files
authored
feat(javascript): allow custom connect timeout (#3010)
1 parent 4e6655a commit 96e6206

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

clients/algoliasearch-client-javascript/packages/client-common/src/transporter/createTransporter.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,14 @@ export function createTransporter({
151151
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
152152
}
153153

154-
let responseTimeout = requestOptions.timeout;
155-
if (responseTimeout === undefined) {
156-
responseTimeout = isRead ? timeouts.read : timeouts.write;
157-
}
154+
let responseTimeout = isRead ? requestOptions.timeouts?.read || timeouts.read : requestOptions.timeouts?.write || timeouts.write;
158155

159156
const payload: EndRequest = {
160157
data,
161158
headers,
162159
method: request.method,
163160
url: serializeUrl(host, request.path, queryParameters),
164-
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
161+
connectTimeout: getTimeout(timeoutsCount, requestOptions.timeouts?.connect || timeouts.connect),
165162
responseTimeout: getTimeout(timeoutsCount, responseTimeout),
166163
};
167164

clients/algoliasearch-client-javascript/packages/client-common/src/types/transporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type RequestOptions = Pick<Request, 'cacheable'> & {
1111
* the given timeout will be applied. But the transporter layer may
1212
* increase this timeout if there is need for it.
1313
*/
14-
timeout?: number;
14+
timeouts?: Partial<Timeouts>;
1515

1616
/**
1717
* Custom headers for the request. This headers are

0 commit comments

Comments
 (0)