Skip to content

Commit

Permalink
🐛 FIX: error message for countries not found or without cases (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eronmmer committed Apr 30, 2020
1 parent 491b2de commit 8a587a0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions utils/getCountry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ module.exports = async (spinner, table, states, countryName, options) => {
const [err, response] = await to(
axios.get(`https://corona.lmao.ninja/v2/countries/${countryName}`)
);
handleError(`API is down, try again later.`, err, false);
const thisCountry = response.data;

if (response.data === 'Country not found') {
if (err && err.response.status === 404) {
spinner.stopAndPersist();
console.log(
`${red(
`${sym.error} Nops. A country named "${countryName}" does not exist`
`${sym.error} Oops. A country named "${countryName}" does not exist or has no cases...`
)}\n`
);
process.exit(0);
}

handleError(`API is down, try again later.`, err, false);
const thisCountry = response.data;

// Format.
const format = numberFormat(options.json);
Expand Down

0 comments on commit 8a587a0

Please sign in to comment.