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
+5 -7
View File
@@ -16,9 +16,8 @@ module.exports = class CurrencyCommand extends Command {
prompt: 'What currency code do you want to use as the base?',
type: 'string',
validate: base => {
if(codes.includes(base.toUpperCase()))
return true;
return `${base} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
if(codes.includes(base.toUpperCase())) return true;
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
},
parse: base => base.toUpperCase()
},
@@ -27,9 +26,8 @@ module.exports = class CurrencyCommand extends Command {
prompt: 'What currency code do you want to convert to?',
type: 'string',
validate: to => {
if(codes.includes(to.toUpperCase()))
return true;
return `${to} is not a valid currency code. Use \`help currency\` to view a list of codes.`;
if(codes.includes(to.toUpperCase())) return true;
return 'Invalid Currency Code. Use `help currency` to view a list of currency codes.';
},
parse: to => to.toUpperCase()
},
@@ -52,7 +50,7 @@ module.exports = class CurrencyCommand extends Command {
const converted = rate * amount;
return msg.say(`${amount} ${base} is ${converted} ${to}.`);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -2
View File
@@ -17,8 +17,7 @@ module.exports = class EasterEggCommand extends Command {
prompt: 'What easter egg do you want to view?',
type: 'string',
validate: tag => {
if(eastereggs[tag.toLowerCase()])
return true;
if(eastereggs[tag.toLowerCase()]) return true;
return 'Nope, that\'s not a valid easter egg. Try again!';
},
parse: tag => tag.toLowerCase()
+5 -7
View File
@@ -15,9 +15,8 @@ module.exports = class StrawpollCommand extends Command {
prompt: 'What would you like the title of the Strawpoll to be?',
type: 'string',
validate: title => {
if(title.length < 200)
return true;
return `Please keep your title under 200 characters, you have ${title.length}.`;
if(title.length < 200) return true;
return 'Invalid Title. Title must be under 200 characters.';
}
},
{
@@ -26,9 +25,8 @@ module.exports = class StrawpollCommand extends Command {
type: 'string',
infinite: true,
validate: choice => {
if(choice.length < 160)
return true;
return `Please keep your options under 160 characters each, you have ${choice.length}.`;
if(choice.length < 160) return true;
return 'Invalid Choice. Choices must be under 140 characters each.';
}
}
]
@@ -50,7 +48,7 @@ module.exports = class StrawpollCommand extends Command {
http://strawpoll.me/${body.id}
`);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -1
View File
@@ -31,7 +31,7 @@ module.exports = class TodayCommand extends Command {
.setDescription(`${events[random].year}: ${events[random].text}`);
return msg.embed(embed);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};
+1 -1
View File
@@ -29,7 +29,7 @@ module.exports = class WouldYouRatherCommand extends Command {
.setDescription(`${body.choicea} OR ${body.choiceb}?`);
return msg.embed(embed);
} catch(err) {
return msg.say('An Unknown Error Occurred.');
return msg.say(`An Error Occurred: ${err}`);
}
}
};