From ecb3b51bec625de51b8cb71207ac4bccd8c62aa0 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Thu, 13 Jul 2017 18:59:17 +0200 Subject: [PATCH] Re-queue on 5xx status codes for paste fetches --- src/scrapers/pastebin-com.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scrapers/pastebin-com.js b/src/scrapers/pastebin-com.js index 3310951..5445286 100644 --- a/src/scrapers/pastebin-com.js +++ b/src/scrapers/pastebin-com.js @@ -35,8 +35,12 @@ module.exports = function createPastebinComScraper(options = {}) { return bhttp.get(`https://pastebin.com/api_scrape_item.php?i=${task.pasteKey}`); }).then((response) => { if (response.statusCode !== 200) { - // FIXME: Retry! - throw new errors.HttpError(`Encountered a non-200 status code for Pastebin.com while retrieving a raw paste: ${response.statusCode}`, {type: "statusCode"}); + if (response.statusCode >= 500 && response.statusCode < 600) { + // FIXME: The below logic could lead to an infinite recursion if Pastebin never comes back up + return queue.push("fetchPaste", task); + } else { + throw new errors.HttpError(`Encountered a non-200 status code for Pastebin.com while retrieving a raw paste: ${response.statusCode}`, {type: "statusCode"}); + } } else if (response.body.toString().indexOf("Please slow down, you are hitting our servers unnecessarily hard!") === 0) { throw new errors.HttpError("Got rate-limited!", {type: "rateLimited"}); } else {