Better Error Handling

This commit is contained in:
Daniel Odendahl Jr
2017-05-05 21:37:30 +00:00
parent d8a773958d
commit 13cbd23f2f
54 changed files with 120 additions and 156 deletions
+2 -1
View File
@@ -28,13 +28,14 @@ module.exports = class DefineCommand extends Command {
try {
const { body } = await request
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions?limit=1&includeRelated=false&useCanonical=false&api_key=${process.env.WORDNIK_KEY}`);
if(body.length === 0) throw new Error('No Results.');
const embed = new RichEmbed()
.setColor(0x9797FF)
.setTitle(body[0].word)
.setDescription(body[0].text);
return msg.embed(embed);
} catch(err) {
return msg.say('An Error Occurred. The word may not have been found.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};