Skip to content

Commit a5b4202

Browse files
authored
[Docs] Handle timeouts in API crawler (#19276)
1 parent 90a6090 commit a5b4202

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

bin/crawl-api-links.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ async function checkLinks() {
4343
continue; // Skip if the link is empty
4444
}
4545

46-
await page.goto(link, {
47-
waitUntil: "networkidle0",
48-
timeout: navigationTimeout,
49-
});
46+
try {
47+
await page.goto(link, {
48+
waitUntil: "networkidle0",
49+
timeout: navigationTimeout,
50+
});
51+
} catch (e) {
52+
console.log(
53+
` WARNING: Error loading Dev Docs page: ${e.message}... Skipping.`,
54+
);
55+
continue;
56+
}
5057

5158
const pageLinks = await page.$$eval("a", (elements) =>
5259
elements.map((el) => el.href),
@@ -62,18 +69,28 @@ async function checkLinks() {
6269
pageLink.startsWith("/api/resources/")
6370
) {
6471
console.log(`Evaluating link: ${pageLink}`);
65-
const response = await page.goto(pageLink, {
66-
waitUntil: "networkidle0",
67-
timeout: navigationTimeout,
68-
});
69-
visitedLinks.push(pageLink);
72+
73+
let response = null;
74+
75+
try {
76+
response = await page.goto(pageLink, {
77+
waitUntil: "networkidle0",
78+
timeout: navigationTimeout,
79+
});
80+
visitedLinks.push(pageLink);
81+
} catch (e) {
82+
console.log(
83+
` WARNING: Error loading API page: ${e.message}... Skipping.`,
84+
);
85+
continue;
86+
}
7087

7188
if (response) {
7289
if (response.status() === 404) {
7390
brokenLinks.push(pageLink);
7491
}
7592
} else {
76-
console.log("WARNING: Didn't receive a response... skipping.");
93+
console.log(" WARNING: Didn't receive a response... skipping.");
7794
}
7895
}
7996
}

0 commit comments

Comments
 (0)