From 59636520c6c755557164c2bb31d03f965428eac9 Mon Sep 17 00:00:00 2001 From: David Balderston Date: Sat, 10 Dec 2022 11:45:44 -0800 Subject: [PATCH] Update getMatch halfs split error for forfeited maps (#623) Closes #622 * Adds if statement for if the half stats exist since they do not when a team forfeits a map. If it doesn't exist, just default to 0 rounds on each half. --- src/endpoints/getMatch.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/endpoints/getMatch.ts b/src/endpoints/getMatch.ts index af9a0f62..cc1ed3f6 100644 --- a/src/endpoints/getMatch.ts +++ b/src/endpoints/getMatch.ts @@ -331,13 +331,16 @@ function getMaps($: HLTVPage): MapResult[] { if (!isNaN(team1TotalRounds) && !isNaN(team2TotalRounds)) { const halfsString = mapEl.find('.results-center-half-score').trimText()! - const halfs = halfsString - .split(' ') - .map((x) => x.replace(/\(|\)|;/g, '')) - .map((half) => ({ - team1Rounds: Number(half.split(':')[0]), - team2Rounds: Number(half.split(':')[1]) - })) + let halfs = [{team1Rounds: 0, team2Rounds: 0}, {team1Rounds: 0, team2Rounds: 0}] + if (halfsString) { + halfs = halfsString + .split(' ') + .map((x) => x.replace(/\(|\)|;/g, '')) + .map((half) => ({ + team1Rounds: Number(half.split(':')[0]), + team2Rounds: Number(half.split(':')[1]) + })) + } result = { team1TotalRounds,