From 0a13bb075036b3f72a6340d18e6967c7543112dc Mon Sep 17 00:00:00 2001 From: Cleve Stuart Date: Mon, 21 Aug 2023 09:34:56 -0700 Subject: [PATCH] Only use AbortSignal.timeout if it exists --- src/http-client/fetch-client.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/http-client/fetch-client.ts b/src/http-client/fetch-client.ts index 24a06a09..b4c1b721 100644 --- a/src/http-client/fetch-client.ts +++ b/src/http-client/fetch-client.ts @@ -28,11 +28,21 @@ export class FetchClient implements HTTPClient { method, client_timeout_ms, }: HTTPRequest): Promise { + const signal = + AbortSignal.timeout === undefined + ? (() => { + const controller = new AbortController(); + const signal = controller.signal; + setTimeout(() => controller.abort(), client_timeout_ms); + return signal; + })() + : AbortSignal.timeout(client_timeout_ms); + const response = await fetch(this.#url, { method, headers: { ...requestHeaders, "Content-Type": "application/json" }, body: JSON.stringify(data), - signal: AbortSignal.timeout(client_timeout_ms), + signal, keepalive: this.#keepalive, }).catch((error) => { throw new NetworkError("The network connection encountered a problem.", {