Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/internal/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export async function _api<T>(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;
Expand All @@ -52,11 +57,6 @@ export async function _api<T>(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 {
Expand Down