Skip to content

Commit 90e3757

Browse files
Merge pull request #238 from manoj-k04/AIMCP-170-Accessibiy-scan-fix
Aimcp 170 accessibiy scan fix
2 parents 4c290be + 60e4ca9 commit 90e3757

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,33 @@ 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
55+
? { Authorization: basicAuthHeader }
56+
: undefined,
57+
});
58+
const reportData: ReportResponse = reportResp.data;
59+
if (!reportData.success) {
60+
throw new Error(`Failed to fetch report: ${reportData.error}`);
61+
}
62+
const link = reportData.data?.reportLink;
63+
if (link) {
64+
return link;
65+
}
66+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
5667
}
57-
return reportData.data.reportLink;
68+
69+
throw new Error(
70+
`Report link was not available after ${maxAttempts} attempts. The CSV generation may still be in progress.`,
71+
);
5872
}
5973
}

0 commit comments

Comments
 (0)