Skip to content

Commit 3787a81

Browse files
committed
fix(rest): remove timeout from upload and commit requests
1 parent 47cdc44 commit 3787a81

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typings/
5959

6060
# Optional npm cache directory
6161
.npm
62+
.bun
6263

6364
# Optional eslint cache
6465
.eslintcache
@@ -112,3 +113,7 @@ dist
112113

113114
# TernJS port file
114115
.tern-port
116+
117+
# Bun lock
118+
bun.lock
119+
bun.lockb

src/services/discloud/REST.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default class REST implements IApi {
9191
if (requestToken) this.rateLimiter.verify(requestToken);
9292

9393
const isReadonly = !config.method || config.method === RequestMethod.Get;
94+
const hasBody = config.method === RequestMethod.Post || config.method === RequestMethod.Put;
9495
const retries = isReadonly ? MAX_RETRIES : 1;
9596

9697
let lastError: unknown;
@@ -102,11 +103,11 @@ export default class REST implements IApi {
102103
await sleep(delay);
103104
}
104105

105-
const controller = new AbortController();
106-
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
106+
const controller = hasBody ? null : new AbortController();
107+
const timeout = controller ? setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS) : null;
107108

108109
try {
109-
const response = await fetch(url, { ...config, signal: controller.signal });
110+
const response = await fetch(url, { ...config, ...(controller ? { signal: controller.signal } : {}) });
110111

111112
if (requestToken) this.#handleResponseHeaders(response.headers, requestToken);
112113

@@ -138,7 +139,7 @@ export default class REST implements IApi {
138139
if (attempt < retries - 1) continue;
139140
throw err;
140141
} finally {
141-
clearTimeout(timeout);
142+
if (timeout) clearTimeout(timeout);
142143
}
143144
}
144145

0 commit comments

Comments
 (0)