-2

my codes as below why am i getting such an error ;

" ReferenceError: err is not defined "

else if (processMethod.toUpperCase() === "COVID") {
    console.log("white", "get covid statics...");
    targetCountry = (await covid.parseCountry(UK)).countryid;
    if (err.message === "Failed to get country." || err.message === "Invalid Country Code") {

        const ErrMsg2 = new Discord.RichEmbed()
            ErrMsg2.setColor(0x00AE86)
            ErrMsg2.setTimestamp()
            ErrMsg2.setAuthor(message.author.username, message.author.avatarURL)
            ErrMsg2.setThumbnail(message.guild.iconURL)
            ErrMsg2.setDescription(`Failed Try Again`)
            ErrMsg2.setFooter("COVID SERVICES")
            message.channel.sendEmbed(ErrMsg2);
    }

}
Jaromanda X
  • 53,868
  • 5
  • 73
  • 87
  • 3
    so, where is `err` defined? you've failed to show that - perhaps you need a try/catch(err) since you're using async/await ... that's how you handle errors when using await – Jaromanda X May 23 '20 at 00:26

1 Answers1

0

If you are doing error handling you need to detect the error first, try using try{} and catch(){}

for your code

try {
   targetCountry = (await covid.parseCountry(UK)).countryid;
}
catch (err) {
    if (err.message === "Failed to get country." || err.message === "Invalid Country Code") { 
        // ...
    }
}
mmoomocow
  • 1,173
  • 7
  • 27