Skip to content

Commit

Permalink
[gelbooru] display error for invalid API responses (#4903)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 6, 2024
1 parent c25bdba commit cbfb7bf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gallery_dl/extractor/gelbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ def _api_request(self, params, key="post"):
url = self.root + "/index.php?page=dapi&q=index&json=1"
data = self.request(url, params=params).json()

if key not in data:
return ()
try:
posts = data[key]
except KeyError:
self.log.error("Incomplete API response (missing '%s')", key)
self.log.debug("%s", data)
return []

posts = data[key]
if not isinstance(posts, list):
return (posts,)
return posts
Expand Down

0 comments on commit cbfb7bf

Please sign in to comment.