From 7bc39ca8b0bb826f83a2f76f83fb500569604b59 Mon Sep 17 00:00:00 2001 From: Dalton Date: Fri, 7 Dec 2018 17:19:53 -0800 Subject: [PATCH] added imgur error handle --- bot.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bot.js b/bot.js index e094fb6..ad636bd 100644 --- a/bot.js +++ b/bot.js @@ -128,8 +128,12 @@ function imgurRequest(subreddit, page_max) { req.onreadystatechange = function () { if (req.readyState === 4 && req.status === 200) { if (req.responseText !== "Not found") { - var json = JSON.parse(req.responseText); - returnText = json.data[getRandomInt(0, json.data.length - 1)].link; + try { + var json = JSON.parse(req.responseText); + returnText = json.data[getRandomInt(0, json.data.length - 1)].link; + } catch (error) { + // Ignore the error and let the calling method handle the empty string. + } } } };