Skip to content

Commit 4e3cb10

Browse files
committed
fix: poll for reportLink in accessibility scan (AIMCP-170)
1 parent 4c290be commit 4e3cb10

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

src/tools/accessiblity-utils/report-fetcher.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,31 @@ export class AccessibilityReportFetcher {
4141
}
4242
const taskId = initData.data.task_id;
4343

44-
// Fetch the generated CSV link
44+
// Poll for the generated CSV link (task is async, may take a few seconds)
4545
const reportUrl = `https://api-accessibility.browserstack.com/api/website-scanner/v1/scans/${scanId}/scan_runs/issues?task_id=${encodeURIComponent(
4646
taskId,
4747
)}`;
48-
// Use apiClient for the report link request as well
49-
const reportResp = await apiClient.get({
50-
url: reportUrl,
51-
headers: basicAuthHeader ? { Authorization: basicAuthHeader } : undefined,
52-
});
53-
const reportData: ReportResponse = reportResp.data;
54-
if (!reportData.success) {
55-
throw new Error(`Failed to fetch report: ${reportData.error}`);
48+
const maxAttempts = 3;
49+
const pollIntervalMs = 2000;
50+
51+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
52+
const reportResp = await apiClient.get({
53+
url: reportUrl,
54+
headers: basicAuthHeader ? { Authorization: basicAuthHeader } : undefined,
55+
});
56+
const reportData: ReportResponse = reportResp.data;
57+
if (!reportData.success) {
58+
throw new Error(`Failed to fetch report: ${reportData.error}`);
59+
}
60+
const link = reportData.data?.reportLink;
61+
if (link) {
62+
return link;
63+
}
64+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
5665
}
57-
return reportData.data.reportLink;
66+
67+
throw new Error(
68+
`Report link was not available after ${maxAttempts} attempts. The CSV generation may still be in progress.`,
69+
);
5870
}
5971
}

0 commit comments

Comments
 (0)