diff --git a/dist/src/classes/RequestClient.js b/dist/src/classes/RequestClient.js index 4a3357a3a71e993e49dbf4511be7f39aeec03755..cae09147c4016ff15ee09c7a0c679a6cd6e374e0 100644 --- a/dist/src/classes/RequestClient.js +++ b/dist/src/classes/RequestClient.js @@ -118,6 +118,9 @@ export class RequestClient { } } this.abortController = new AbortController(); + const timeoutMs = typeof this.options.timeout === "number" && this.options.timeout > 0 + ? this.options.timeout + : undefined; let body; if (data?.body && typeof data.body === "object" && @@ -178,12 +181,26 @@ export class RequestClient { body = JSON.stringify(data.body); } } - const response = await fetch(url, { - method, - headers, - body, - signal: this.abortController.signal - }); + let timeoutId; + if (timeoutMs !== undefined) { + timeoutId = setTimeout(() => { + this.abortController?.abort(); + }, timeoutMs); + } + let response; + try { + response = await fetch(url, { + method, + headers, + body, + signal: this.abortController.signal + }); + } + finally { + if (timeoutId) { + clearTimeout(timeoutId); + } + } let rawBody = ""; let parsedBody; try {