Skip to content

Commit

Permalink
catch IGDB API error
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed Dec 25, 2024
1 parent a8a6028 commit dfc1f3e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions catalog/sites/igdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def api_query(cls, p, q):
r = BasicDownloader(key).download().json()
else:
_wrapper = IGDBWrapper(settings.IGDB_CLIENT_ID, _igdb_access_token())
r = json.loads(_wrapper.api_request(p, q)) # type: ignore
try:
r = json.loads(_wrapper.api_request(p, q)) # type: ignore
except requests.HTTPError as e:
logger.error("IGDB API: {e}", extra={"exception": e})
return []
if settings.DOWNLOADER_SAVEDIR:
with open(
settings.DOWNLOADER_SAVEDIR + "/" + get_mock_file(key),
Expand Down Expand Up @@ -119,7 +123,10 @@ def search(cls, q, limit: int, offset: int = 0):

def scrape(self):
fields = "*, cover.url, genres.name, platforms.name, involved_companies.*, involved_companies.company.name"
r = self.api_query("games", f'fields {fields}; where url = "{self.url}";')[0]
r = self.api_query("games", f'fields {fields}; where url = "{self.url}";')
if not r:
raise ParseError(self, "no data")
r = r[0]
brief = r["summary"] if "summary" in r else ""
brief += "\n\n" + r["storyline"] if "storyline" in r else ""
developer = None
Expand Down

0 comments on commit dfc1f3e

Please sign in to comment.