Skip to content

Commit e58b82f

Browse files
stainless-botRobertCraigie
authored andcommitted
chore(client): detect node and deno timeout errors
chore: unknown commit message
1 parent f39bc36 commit e58b82f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ export class OpenAI {
486486
if (isAbortError(response)) {
487487
throw new Errors.APIConnectionTimeoutError();
488488
}
489+
// detect native connection timeout errors
490+
// deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
491+
// undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
492+
// others do not provide enough information to distinguish timeouts from other connection errors
493+
if (/timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''))) {
494+
throw new Errors.APIConnectionTimeoutError();
495+
}
489496
throw new Errors.APIConnectionError({ cause: response });
490497
}
491498

0 commit comments

Comments
 (0)