Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 FIX: error message for countries not found or without cases #51

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions utils/getCountry.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ module.exports = async (spinner, table, states, countryName) => {
const [err, response] = await to(
axios.get(`https://corona.lmao.ninja/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;

table.push([
`—`,
Expand Down