From dfc1f3ed142cbd707db769f7ff8dd1b4ce3ba953 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 25 Dec 2024 16:02:34 -0500 Subject: [PATCH] catch IGDB API error --- catalog/sites/igdb.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/catalog/sites/igdb.py b/catalog/sites/igdb.py index f27721fd..7f09f1ce 100644 --- a/catalog/sites/igdb.py +++ b/catalog/sites/igdb.py @@ -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), @@ -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