From f83e6f29f72af002d7838f56d80970f24c0700e2 Mon Sep 17 00:00:00 2001 From: Dalton Date: Fri, 7 Dec 2018 20:54:31 -0800 Subject: [PATCH] don't check json if reddit doesn't exist --- bot.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bot.js b/bot.js index 717a7bb..8d1eb5a 100644 --- a/bot.js +++ b/bot.js @@ -186,11 +186,13 @@ function imgurRequest(subreddit, page_max) { // Abstracted Reddit Json media grab. function handleRedditJson(data) { let json = data.json(); - for (let i = 0; i < json.data.children.length; i++) { - let rand = getRandomInt(0, json.data.children.length - 1); + if(json.data.children) { + for (let i = 0; i < json.data.children.length; i++) { + let rand = getRandomInt(0, json.data.children.length - 1); - if (json.data.children[rand].data.post_hint === "image" || json.data.children[rand].data.post_hint === "link" || json.data.children.data.post_hint === "rich:video") { - return json.data.children[rand].data.url; + if (json.data.children[rand].data.post_hint === "image" || json.data.children[rand].data.post_hint === "link" || json.data.children.data.post_hint === "rich:video") { + return json.data.children[rand].data.url; + } } } // What if we don't find anything i.e. r/dogs but its valid subreddit.