Convert everything to superagent properly

This commit is contained in:
Daniel Odendahl Jr
2018-06-08 15:36:21 +00:00
parent 63f3398858
commit b4c815f403
17 changed files with 163 additions and 155 deletions
+2 -2
View File
@@ -21,10 +21,10 @@ module.exports = class HttpCatCommand extends Command {
async run(msg, { code }) {
try {
const { body, headers } = await request.get(`https://http.cat/${code}.jpg`);
if (headers['content-type'] === 'text/html') return msg.say('Could not find any results.');
const { body } = await request.get(`https://http.cat/${code}.jpg`);
return msg.say({ files: [{ attachment: body, name: `${code}.jpg` }] });
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}