From 10f8009101516d7297dfcc6ce2c96eb68a8be7a5 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 6 Dec 2020 15:39:28 +1300 Subject: [PATCH] Gracefully fail on feed fetch for invalid channel --- extractors/channel.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/extractors/channel.py b/extractors/channel.py index 6a969e0..ef827cc 100644 --- a/extractors/channel.py +++ b/extractors/channel.py @@ -127,7 +127,13 @@ def extract_channel_latest(ucid): return channel_latest_cache[ucid] with requests.get("https://www.youtube.com/feeds/videos.xml?channel_id={}".format(ucid)) as r: - r.raise_for_status() + if r.status_code == 404: + cherrypy.response.status = 404 + return { + "error": "Channel does not exist.", + "identifier": "NOT_FOUND" + } + feed = ET.fromstring(r.content) author_container = feed.find("{http://www.w3.org/2005/Atom}author") author = author_container.find("{http://www.w3.org/2005/Atom}name").text @@ -171,8 +177,8 @@ def extract_channel_latest(ucid): "error": "YouTube did not provide published dates for any feed items. This is usually temporary - refresh in a few minutes.", "identifier": "PUBLISHED_DATES_NOT_PROVIDED" } - else: - with channel_latest_cache_lock: - channel_latest_cache[ucid] = results - return results + with channel_latest_cache_lock: + channel_latest_cache[ucid] = results + + return results