diff --git a/src/internal/request.ts b/src/internal/request.ts index 737625e..1667ce7 100644 --- a/src/internal/request.ts +++ b/src/internal/request.ts @@ -39,6 +39,11 @@ export async function _api(ctx: TestRailCtx, method: string, path: string, { // @ts-ignore - intentionally throws "ReferrerError" if "fetch" is not available const response = await (ctx.implementations?.fetch || fetch)(url, { method, body, headers, signal: ctx.signal }); + // Content-Type based response + const result = response.headers.get('Content-Type')?.includes('json') + ? await response.json().catch(() => ({})) + : await response.blob(); + // Retry on 429 Too Many Requests if (response.status === 429) { const retryAfter = parseInt(response.headers.get('Retry-After') || '1') * 1000; @@ -52,11 +57,6 @@ export async function _api(ctx: TestRailCtx, method: string, path: string, { continue; } - // Content-Type based response - const result = response.headers.get('Content-Type')?.includes('json') - ? await response.json().catch(() => ({})) - : await response.blob(); - if (response.ok) { return result; } else {