in packages/synthetics-sdk-broken-links/src/link_utils.ts [150:215]
function parseFollowedLinks(
followed_links: BrokenLinksResultV1_SyntheticLinkResult[]
) {
const broken_links_result: BrokenLinksResultV1 = {
link_count: 0,
passing_link_count: 0,
failing_link_count: 0,
unreachable_count: 0,
status2xx_count: 0,
status3xx_count: 0,
status4xx_count: 0,
status5xx_count: 0,
options: {} as BrokenLinksResultV1_BrokenLinkCheckerOptions,
origin_link_result: {} as BrokenLinksResultV1_SyntheticLinkResult,
followed_link_results: [],
execution_data_storage_path: '',
errors: [],
};
for (const link of followed_links) {
if (link.link_passed === undefined) continue;
link.is_origin
? (broken_links_result.origin_link_result = link)
: broken_links_result.followed_link_results.push(link);
broken_links_result.link_count = (broken_links_result.link_count ?? 0) + 1;
if (link.link_passed) {
broken_links_result.passing_link_count =
(broken_links_result.passing_link_count ?? 0) + 1;
} else {
broken_links_result.failing_link_count =
(broken_links_result.failing_link_count ?? 0) + 1;
}
switch (Math.floor(link.status_code! / 100)) {
case 2:
broken_links_result.status2xx_count =
(broken_links_result.status2xx_count ?? 0) + 1;
break;
case 3:
broken_links_result.status3xx_count =
(broken_links_result.status3xx_count ?? 0) + 1;
break;
case 4:
broken_links_result.status4xx_count =
(broken_links_result.status4xx_count ?? 0) + 1;
break;
case 5:
broken_links_result.status5xx_count =
(broken_links_result.status5xx_count ?? 0) + 1;
break;
default:
// Handle other status codes if needed
broken_links_result.unreachable_count =
(broken_links_result.unreachable_count ?? 0) + 1;
break;
}
}
return broken_links_result;
}