46 lines
1.4 KiB
Diff
46 lines
1.4 KiB
Diff
--- a/dist/src/classes/RequestClient.js
|
|
+++ b/dist/src/classes/RequestClient.js
|
|
@@ -86,6 +86,9 @@
|
|
}
|
|
}
|
|
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" &&
|
|
@@ -146,12 +149,26 @@
|
|
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);
|
|
+ }
|
|
+ }
|
|
if (response.status === 429) {
|
|
const responseBody = await response.json();
|
|
const rateLimitError = new RateLimitError(response, responseBody);
|