Skip to content

Commit

Permalink
馃憣 IMPROVE: Missing Country
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadawais committed Apr 30, 2020
1 parent 8a587a0 commit eb42bab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
19 changes: 19 additions & 0 deletions utils/exitCountry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { red } = require('chalk');
const sym = require('log-symbols');

module.exports = (err, spinner, countryName) => {
if (
err &&
err.response &&
err.response.status &&
err.response.status === 404
) {
spinner.stopAndPersist();
console.log(
`${red(
`${sym.error} Oops. A country named "${countryName}" doesn't exist鈥
)}\n`
);
process.exit(0);
}
};
16 changes: 3 additions & 13 deletions utils/getCountry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { red } = require('chalk');
const axios = require('axios');
const sym = require('log-symbols');
const numberFormat = require('./numberFormat');
const exitCountry = require('./exitCountry');
const to = require('await-to-js').default;
const handleError = require('cli-handle-error');

Expand All @@ -10,17 +9,8 @@ module.exports = async (spinner, table, states, countryName, options) => {
const [err, response] = await to(
axios.get(`https://corona.lmao.ninja/v2/countries/${countryName}`)
);

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

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

Expand Down

0 comments on commit eb42bab

Please sign in to comment.