From 2564f742d48cc24f3f461a92b1d3c3df26efd056 Mon Sep 17 00:00:00 2001 From: Emily J Date: Wed, 28 Apr 2021 14:50:58 +1000 Subject: [PATCH] dont silently fail when API fetch fails --- src/commands/catfact.js | 3 +++ src/commands/dogfact.js | 5 ++++- src/commands/garfield.js | 3 +++ src/commands/inspirobot.js | 5 ++++- src/commands/kitsune.js | 5 ++++- src/commands/neko.js | 5 ++++- src/commands/nekogif.js | 5 ++++- src/commands/restart.js | 2 ++ src/commands/rip.js | 3 +++ src/commands/wag.js | 5 ++++- src/commands/yoda.js | 5 ++++- 11 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/commands/catfact.js b/src/commands/catfact.js index 366999e..c190cd0 100644 --- a/src/commands/catfact.js +++ b/src/commands/catfact.js @@ -5,6 +5,9 @@ exports.run = async (bot, message, args) => { fetch('https://catfact.ninja/facts') .then(res => res.json()) .then(json => message.channel.send(`__**Did you know?**__\n${json.data[0].fact}`)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); }; diff --git a/src/commands/dogfact.js b/src/commands/dogfact.js index fca8a62..d962a12 100644 --- a/src/commands/dogfact.js +++ b/src/commands/dogfact.js @@ -4,7 +4,10 @@ exports.run = async (bot, message, args) => { try{ fetch('https://dog-api.kinduff.com/api/facts') .then(res => res.json()) - .then(json => message.channel.send(`__**Did you know?**__\n ${json.facts[0]}`)); + .then(json => message.channel.send(`__**Did you know?**__\n ${json.facts[0]}`)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); }; diff --git a/src/commands/garfield.js b/src/commands/garfield.js index 597fe16..0c262f7 100644 --- a/src/commands/garfield.js +++ b/src/commands/garfield.js @@ -12,6 +12,9 @@ exports.run = async (client, message) => { .setURL('https://www.mezzacotta.net/garfield/?comic=' + json.data.number) .setImage(json.data.image.src); message.channel.send(embed) + }) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); }); message.channel.stopTyping(); } catch (err) { diff --git a/src/commands/inspirobot.js b/src/commands/inspirobot.js index 17a028f..f7a5865 100644 --- a/src/commands/inspirobot.js +++ b/src/commands/inspirobot.js @@ -4,7 +4,10 @@ exports.run = async (client, message) => { try { fetch('http://inspirobot.me/api?generate=true') .then(res => res.text()) - .then(body => message.channel.send({files: [new Discord.MessageAttachment(body)]})); + .then(body => message.channel.send({files: [new Discord.MessageAttachment(body)]})) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); message.channel.stopTyping(); } catch (err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`) diff --git a/src/commands/kitsune.js b/src/commands/kitsune.js index 27746fc..7abe85f 100644 --- a/src/commands/kitsune.js +++ b/src/commands/kitsune.js @@ -4,7 +4,10 @@ exports.run = async (client, message, args) => { try{ fetch(`https://purrbot.site/api/img/sfw/kitsune/img/`) .then(res => res.json()) - .then(json => message.channel.send(json.link)); + .then(json => message.channel.send(json.link)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); message.channel.stopTyping(); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); diff --git a/src/commands/neko.js b/src/commands/neko.js index 7694a91..0095ba3 100644 --- a/src/commands/neko.js +++ b/src/commands/neko.js @@ -4,7 +4,10 @@ exports.run = async (client, message, args) => { try{ fetch(`https://purrbot.site/api/img/sfw/neko/img/`) .then(res => res.json()) - .then(json => message.channel.send(json.link)); + .then(json => message.channel.send(json.link)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); message.channel.stopTyping(); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); diff --git a/src/commands/nekogif.js b/src/commands/nekogif.js index ae6c91d..122d6de 100644 --- a/src/commands/nekogif.js +++ b/src/commands/nekogif.js @@ -4,7 +4,10 @@ exports.run = async (client, message, args) => { try{ fetch(`https://purrbot.site/api/img/sfw/neko/gif/`) .then(res => res.json()) - .then(json => message.channel.send(json.link)); + .then(json => message.channel.send(json.link)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); message.channel.stopTyping(); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); diff --git a/src/commands/restart.js b/src/commands/restart.js index fb174fc..dfd005a 100644 --- a/src/commands/restart.js +++ b/src/commands/restart.js @@ -13,6 +13,8 @@ exports.run = (client, message) => {// eslint-disable-line no-unused-vars method: 'post', body: JSON.stringify({ 'signal': 'restart' }), headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${client.config.server}` } + }).catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); }); }; diff --git a/src/commands/rip.js b/src/commands/rip.js index 968e08a..5039140 100644 --- a/src/commands/rip.js +++ b/src/commands/rip.js @@ -6,6 +6,9 @@ exports.run = (client, message) => { fetch('http://mityurl.com/y/yKsQ/r', { redirect: 'follow' }) .then(res => res) .then(res => message.channel.send(`>:] ${res.url}`)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); }; diff --git a/src/commands/wag.js b/src/commands/wag.js index 77e5360..a3a5a04 100644 --- a/src/commands/wag.js +++ b/src/commands/wag.js @@ -4,7 +4,10 @@ exports.run = async (client, message, args) => { try{ fetch(`https://purrbot.site/api/img/sfw/tail/gif/`) .then(res => res.json()) - .then(json => message.channel.send(json.link)); + .then(json => message.channel.send(json.link)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); message.channel.stopTyping(); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); diff --git a/src/commands/yoda.js b/src/commands/yoda.js index 496b929..9b71065 100644 --- a/src/commands/yoda.js +++ b/src/commands/yoda.js @@ -9,7 +9,10 @@ exports.run = async (client, message, args) => { try{ fetch(`http://yoda-api.appspot.com/api/v1/yodish?text=${encodeURIComponent(speech.toLowerCase())}`) .then(res => res.json()) - .then(json => message.channel.send(json.yodish)); + .then(json => message.channel.send(json.yodish)) + .catch(err => { + message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`); + }); message.channel.stopTyping(); } catch(err) { message.channel.send(`<:error:466995152976871434> An error has occurred: ${err}`);