added imgur error handle

This commit is contained in:
Dalton
2018-12-07 17:19:53 -08:00
parent 0bacabc40d
commit 7bc39ca8b0

4
bot.js
View File

@@ -128,8 +128,12 @@ function imgurRequest(subreddit, page_max) {
req.onreadystatechange = function () { req.onreadystatechange = function () {
if (req.readyState === 4 && req.status === 200) { if (req.readyState === 4 && req.status === 200) {
if (req.responseText !== "Not found") { if (req.responseText !== "Not found") {
try {
var json = JSON.parse(req.responseText); var json = JSON.parse(req.responseText);
returnText = json.data[getRandomInt(0, json.data.length - 1)].link; returnText = json.data[getRandomInt(0, json.data.length - 1)].link;
} catch (error) {
// Ignore the error and let the calling method handle the empty string.
}
} }
} }
}; };