Skip to content

Commit

Permalink
feat(javascript): allow custom connect timeout
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3010

Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Apr 15, 2024
1 parent 189602a commit cb72883
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
7 changes: 2 additions & 5 deletions packages/client-common/src/transporter/createTransporter.ts
Expand Up @@ -151,17 +151,14 @@ export function createTransporter({
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
}

let responseTimeout = requestOptions.timeout;
if (responseTimeout === undefined) {
responseTimeout = isRead ? timeouts.read : timeouts.write;
}
let responseTimeout = isRead ? requestOptions.timeouts?.read || timeouts.read : requestOptions.timeouts?.write || timeouts.write;

const payload: EndRequest = {
data,
headers,
method: request.method,
url: serializeUrl(host, request.path, queryParameters),
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
connectTimeout: getTimeout(timeoutsCount, requestOptions.timeouts?.connect || timeouts.connect),
responseTimeout: getTimeout(timeoutsCount, responseTimeout),
};

Expand Down
2 changes: 1 addition & 1 deletion packages/client-common/src/types/transporter.ts
Expand Up @@ -11,7 +11,7 @@ export type RequestOptions = Pick<Request, 'cacheable'> & {
* the given timeout will be applied. But the transporter layer may
* increase this timeout if there is need for it.
*/
timeout?: number;
timeouts?: Partial<Timeouts>;

/**
* Custom headers for the request. This headers are
Expand Down

0 comments on commit cb72883

Please sign in to comment.