From 8a587a0c9c21fcadfe5b5f3b8ff5138c0e1e170f Mon Sep 17 00:00:00 2001 From: Erons Date: Thu, 30 Apr 2020 10:40:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20error=20message=20for=20c?= =?UTF-8?q?ountries=20not=20found=20or=20without=20cases=20(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/getCountry.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/getCountry.js b/utils/getCountry.js index 7b56875..be44d36 100644 --- a/utils/getCountry.js +++ b/utils/getCountry.js @@ -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);