Skip to content

Commit

Permalink
fix: Catch error when extension doesn't have any ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Mar 30, 2024
1 parent f39781f commit d04b8b9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/crawlers/chrome-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d04b8b9

Please sign in to comment.