Skip to content

Commit ae7e35b

Browse files
authored
fix: consume response body
1 parent 549d8b4 commit ae7e35b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/internal/request.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export async function _api<T>(ctx: TestRailCtx, method: string, path: string, {
3939
// @ts-ignore - intentionally throws "ReferrerError" if "fetch" is not available
4040
const response = await (ctx.implementations?.fetch || fetch)(url, { method, body, headers, signal: ctx.signal });
4141

42+
// Content-Type based response
43+
const result = response.headers.get('Content-Type')?.includes('json')
44+
? await response.json().catch(() => ({}))
45+
: await response.blob();
46+
4247
// Retry on 429 Too Many Requests
4348
if (response.status === 429) {
4449
const retryAfter = parseInt(response.headers.get('Retry-After') || '1') * 1000;
@@ -52,11 +57,6 @@ export async function _api<T>(ctx: TestRailCtx, method: string, path: string, {
5257
continue;
5358
}
5459

55-
// Content-Type based response
56-
const result = response.headers.get('Content-Type')?.includes('json')
57-
? await response.json().catch(() => ({}))
58-
: await response.blob();
59-
6060
if (response.ok) {
6161
return result;
6262
} else {

0 commit comments

Comments
 (0)