From 86d157699af00dc5b2d87d9499baa8027de4aab2 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 14 May 2024 17:05:47 +0200 Subject: [PATCH] better 404 handling in views --- tubearchivist/home/src/download/thumbnails.py | 2 +- tubearchivist/home/views.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tubearchivist/home/src/download/thumbnails.py b/tubearchivist/home/src/download/thumbnails.py index 4cefd847..cf4c485f 100644 --- a/tubearchivist/home/src/download/thumbnails.py +++ b/tubearchivist/home/src/download/thumbnails.py @@ -386,7 +386,7 @@ class ThumbValidator: "query": {"bool": {"should": should_list}}, "_source": ["youtube_id"], } - result = IndexPaginate("ta_video", data).get_results() + result = IndexPaginate("ta_video,ta_download", data).get_results() thumbs_should = {i["youtube_id"] for i in result} return thumbs_should diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index e8903d75..ec7858cf 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -431,6 +431,8 @@ class ChannelIdBaseView(ArchivistResultsView): path = f"ta_channel/_doc/{channel_id}" response, _ = ElasticWrap(path).get() channel_info = SearchProcess(response).process() + if not channel_info: + raise Http404 return channel_info @@ -724,6 +726,9 @@ class PlaylistIdView(ArchivistResultsView): """handle get request""" self.initiate_vars(request) playlist_info, channel_info = self._get_info(playlist_id) + if not playlist_info: + raise Http404 + playlist_name = playlist_info["playlist_name"] self._update_view_data(playlist_id, playlist_info) self.find_results() @@ -874,6 +879,8 @@ class VideoView(MinView): config_handler = AppConfig() response, _ = ElasticWrap(f"ta_video/_doc/{video_id}").get() video_data = SearchProcess(response).process() + if not video_data: + raise Http404 try: rating = video_data["stats"]["average_rating"]