Skip to content

Commit

Permalink
[gelbooru] display error for invalid API responses (mikf#4903)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf authored and bradenhilton committed Feb 5, 2024
1 parent 569d509 commit 879ceca
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 879ceca

Please sign in to comment.