Skip to content

Commit d04b8b9

Browse files
committed
fix: Catch error when extension doesn't have any ratings
1 parent f39781f commit d04b8b9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/crawlers/chrome-crawler.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function crawlExtension(
2121
const { document } = parseHTML(html);
2222

2323
// Uncomment to debug HTML
24-
// Bun.write("chrome.html", document.documentElement.outerHTML);
24+
Bun.write("chrome.html", document.documentElement.outerHTML);
2525

2626
// Basic metadata
2727
const name = metaContent(document, "property=og:title");
@@ -71,10 +71,17 @@ export async function crawlExtension(
7171
const ratingRow = header.querySelector(
7272
"div:first-child > div:nth-child(2) > span:last-child",
7373
);
74-
const rating = extractNumber(
75-
ratingRow.querySelector("span:first-child > span:first-child").textContent,
76-
);
77-
const reviewCount = extractNumber(ratingRow.querySelector("p").textContent);
74+
const rating =
75+
ratingRow != null
76+
? extractNumber(
77+
ratingRow.querySelector("span:first-child > span:first-child")
78+
.textContent,
79+
)
80+
: 0;
81+
const reviewCount =
82+
ratingRow != null
83+
? extractNumber(ratingRow.querySelector("p").textContent)
84+
: 0;
7885

7986
// Details
8087

0 commit comments

Comments
 (0)