Skip to content

Commit b61f88b

Browse files
chore(client): detect node and deno timeout errors (#69)
1 parent ab3a65b commit b61f88b

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
@@ -374,6 +374,13 @@ export class Stainless {
374374
if (isAbortError(response)) {
375375
throw new Errors.APIConnectionTimeoutError();
376376
}
377+
// detect native connection timeout errors
378+
// 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)"
379+
// undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
380+
// others do not provide enough information to distinguish timeouts from other connection errors
381+
if (/timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''))) {
382+
throw new Errors.APIConnectionTimeoutError();
383+
}
377384
throw new Errors.APIConnectionError({ cause: response });
378385
}
379386

0 commit comments

Comments
 (0)