From d04b8b9365b8bf32d36d172fc1c812d1b9cbc2f5 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 30 Mar 2024 08:13:56 -0500 Subject: [PATCH] fix: Catch error when extension doesn't have any ratings --- src/crawlers/chrome-crawler.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/crawlers/chrome-crawler.ts b/src/crawlers/chrome-crawler.ts index 311d35f..11f5731 100644 --- a/src/crawlers/chrome-crawler.ts +++ b/src/crawlers/chrome-crawler.ts @@ -21,7 +21,7 @@ export async function crawlExtension( const { document } = parseHTML(html); // Uncomment to debug HTML - // Bun.write("chrome.html", document.documentElement.outerHTML); + Bun.write("chrome.html", document.documentElement.outerHTML); // Basic metadata const name = metaContent(document, "property=og:title"); @@ -71,10 +71,17 @@ export async function crawlExtension( const ratingRow = header.querySelector( "div:first-child > div:nth-child(2) > span:last-child", ); - const rating = extractNumber( - ratingRow.querySelector("span:first-child > span:first-child").textContent, - ); - const reviewCount = extractNumber(ratingRow.querySelector("p").textContent); + const rating = + ratingRow != null + ? extractNumber( + ratingRow.querySelector("span:first-child > span:first-child") + .textContent, + ) + : 0; + const reviewCount = + ratingRow != null + ? extractNumber(ratingRow.querySelector("p").textContent) + : 0; // Details