mirror of
https://github.com/clarencechaan/ufc-cal.git
synced 2026-10-25 04:17:39 -07:00
Throw error if fighter name cannot be retrieved
This commit is contained in:
1 parent
d09cc09071
commit
997aee6171
1 file changed
+7
-5
+7
-5
@@ -91,11 +91,13 @@ function convertLiToStr(li: HTMLElement) {
|
|||||||
?.textContent?.replaceAll("\n", "")
|
?.textContent?.replaceAll("\n", "")
|
||||||
.replace(/\s+/g, " ")
|
.replace(/\s+/g, " ")
|
||||||
.trim();
|
.trim();
|
||||||
const ranks = [
|
if (!red || !blue) throw new Error("Failed to retrieve fighter names");
|
||||||
...li.querySelectorAll(
|
|
||||||
|
const ranks = li
|
||||||
|
.querySelectorAll(
|
||||||
".c-listing-fight__ranks-row .js-listing-fight__corner-rank span"
|
".c-listing-fight__ranks-row .js-listing-fight__corner-rank span"
|
||||||
),
|
)
|
||||||
].map((rank) => rank?.textContent);
|
.map((rank) => rank?.textContent);
|
||||||
|
|
||||||
const redRankStr = ranks[0] ? ` (${ranks[0]})` : "";
|
const redRankStr = ranks[0] ? ` (${ranks[0]})` : "";
|
||||||
const blueRankStr = ranks[1] ? ` (${ranks[1]})` : "";
|
const blueRankStr = ranks[1] ? ` (${ranks[1]})` : "";
|
||||||
@@ -151,7 +153,7 @@ async function getDetailsFromEventLink(url: URL) {
|
|||||||
const mainCardElements = root.querySelectorAll(
|
const mainCardElements = root.querySelectorAll(
|
||||||
"#main-card .l-listing__item"
|
"#main-card .l-listing__item"
|
||||||
);
|
);
|
||||||
// Check if main card & prelims have been announced
|
// Check if main card and prelims have been announced
|
||||||
if (mainCardElements.length) {
|
if (mainCardElements.length) {
|
||||||
// Main card has been announced, extract prelims
|
// Main card has been announced, extract prelims
|
||||||
const prelimsElements = root.querySelectorAll(
|
const prelimsElements = root.querySelectorAll(
|
||||||
|
|||||||
Reference in new issue
Block a user