dont silently fail when API fetch fails

This commit is contained in:
Emily 2021-04-28 14:50:58 +10:00
parent 2481dacb91
commit 2564f742d4
11 changed files with 39 additions and 7 deletions

View file

@ -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}`);
};

View file

@ -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}`);
};

View file

@ -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) {

View file

@ -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}`)

View file

@ -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}`);

View file

@ -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}`);

View file

@ -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}`);

View file

@ -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}`);
});
};

View file

@ -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}`);
};

View file

@ -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}`);

View file

@ -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}`);