Skip to content

Commit ae12bf8

Browse files
author
Ian Adams
committed
add error message for no games available on given date
1 parent f8951c4 commit ae12bf8

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/command/game/index.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ const getLosAngelesTimezone = date =>
3333
.format();
3434

3535
const getSeason = date => {
36-
const year = R.compose(getYear, parse)(date);
37-
const month = R.compose(getMonth, parse)(date);
36+
const year = R.compose(
37+
getYear,
38+
parse
39+
)(date);
40+
const month = R.compose(
41+
getMonth,
42+
parse
43+
)(date);
3844

3945
if (year < 2012 || (year === 2012 && month < 5)) {
4046
error(
@@ -88,7 +94,12 @@ const game = async option => {
8894
let seasonMetaData;
8995

9096
if (option.date) {
91-
if (R.compose(isValid, parse)(option.date)) {
97+
if (
98+
R.compose(
99+
isValid,
100+
parse
101+
)(option.date)
102+
) {
92103
_date = format(option.date, 'YYYY-MM-DD');
93104
} else {
94105
error('Date is invalid');
@@ -104,15 +115,24 @@ const game = async option => {
104115
error(`Can't find any option ${emoji.get('confused')}`);
105116
process.exit(1);
106117
}
107-
R.compose(cfontsDate, getSeason)(_date);
118+
R.compose(
119+
cfontsDate,
120+
getSeason
121+
)(_date);
108122

109123
const LADate = getLosAngelesTimezone(_date);
110124

111125
try {
112126
const {
113-
sports_content: { games: { game: _gamesData } },
127+
sports_content: {
128+
games: { game: _gamesData },
129+
},
114130
} = await NBA.getGamesFromDate(LADate);
115131
gamesData = _gamesData;
132+
if (!gamesData.length) {
133+
error('No game available on this date.');
134+
process.exit(1);
135+
}
116136
} catch (err) {
117137
catchAPIError(err, 'NBA.getGamesFromDate()');
118138
}

0 commit comments

Comments
 (0)