Handle some error

This commit is contained in:
loicbersier 2019-12-24 19:02:28 +01:00
parent 313826bd23
commit 1ea32f53a6

View file

@ -51,6 +51,8 @@ class FourchanCommand extends Command {
let title = response.threads[i].posts[0].sub; let title = response.threads[i].posts[0].sub;
let description = response.threads[i].posts[0].com; let description = response.threads[i].posts[0].com;
let boardName = boards.getName(args.board);
if (boardName == undefined) boardName = args.board;
// If title or description is undefined, change it to "no title/description" // If title or description is undefined, change it to "no title/description"
if (!description) { if (!description) {
@ -67,7 +69,7 @@ class FourchanCommand extends Command {
.setDescription(htmlToText.fromString(description)) .setDescription(htmlToText.fromString(description))
.setImage(`https://i.4cdn.org/${args.board}/${response.threads[i].posts[0].tim}${response.threads[i].posts[0].ext}`) .setImage(`https://i.4cdn.org/${args.board}/${response.threads[i].posts[0].tim}${response.threads[i].posts[0].ext}`)
.setURL(`https://boards.4chan.org/${args.board}/thread/${response.threads[i].posts[0].no}/${response.threads[i].posts[0].semantic_url}`) .setURL(`https://boards.4chan.org/${args.board}/thread/${response.threads[i].posts[0].no}/${response.threads[i].posts[0].semantic_url}`)
.setFooter(`${boards.getName(args.board)} | ${response.threads[i].posts[0].name} | ${response.threads[i].posts[0].no} | ${response.threads[i].posts[0].now}`); .setFooter(`${boardName} | ${response.threads[i].posts[0].name} | ${response.threads[i].posts[0].no} | ${response.threads[i].posts[0].now}`);
// If file type dosen't work on embed, send it as a link // If file type dosen't work on embed, send it as a link
if (response.threads[i].posts[0].ext == '.webm' || response.threads[i].posts[0].ext == '.pdf' || response.threads[i].posts[0].ext == '.swf') { if (response.threads[i].posts[0].ext == '.webm' || response.threads[i].posts[0].ext == '.pdf' || response.threads[i].posts[0].ext == '.swf') {
@ -77,6 +79,11 @@ class FourchanCommand extends Command {
} else { } else {
message.channel.send(FourchanEmbed); message.channel.send(FourchanEmbed);
} }
})
.catch((err) => {
if (err.type == 'invalid-json') return message.channel.send('Could not find the board');
console.error(err);
return message.channel.send('Uh-oh, an error has occured and i don\'t know why!');
}); });
} }
} }