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
34 changes: 24 additions & 10 deletions src/tools/accessiblity-utils/report-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,33 @@ export class AccessibilityReportFetcher {
}
const taskId = initData.data.task_id;

// Fetch the generated CSV link
// Poll for the generated CSV link (task is async, may take a few seconds)
const reportUrl = `https://api-accessibility.browserstack.com/api/website-scanner/v1/scans/${scanId}/scan_runs/issues?task_id=${encodeURIComponent(
taskId,
)}`;
// Use apiClient for the report link request as well
const reportResp = await apiClient.get({
url: reportUrl,
headers: basicAuthHeader ? { Authorization: basicAuthHeader } : undefined,
});
const reportData: ReportResponse = reportResp.data;
if (!reportData.success) {
throw new Error(`Failed to fetch report: ${reportData.error}`);
const maxAttempts = 3;
const pollIntervalMs = 2000;

for (let attempt = 1; attempt <= maxAttempts; attempt++) {
const reportResp = await apiClient.get({
url: reportUrl,
headers: basicAuthHeader
? { Authorization: basicAuthHeader }
: undefined,
});
const reportData: ReportResponse = reportResp.data;
if (!reportData.success) {
throw new Error(`Failed to fetch report: ${reportData.error}`);
}
const link = reportData.data?.reportLink;
if (link) {
return link;
}
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
}
return reportData.data.reportLink;

throw new Error(
`Report link was not available after ${maxAttempts} attempts. The CSV generation may still be in progress.`,
);
}
}