Skip to content

Commit 8c43693

Browse files
committed
fix igdb search not handling expired token
1 parent 115b1c1 commit 8c43693

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/app/providers/igdb.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def search(query, page):
8888

8989
if data is None:
9090
access_token = get_access_token()
91+
url = f"{base_url}/multiquery"
9192
headers = {
9293
"Client-ID": settings.IGDB_ID,
9394
"Authorization": f"Bearer {access_token}",
@@ -120,13 +121,23 @@ def search(query, page):
120121
response = services.api_request(
121122
Sources.IGDB.value,
122123
"POST",
123-
f"{base_url}/multiquery",
124+
url,
124125
data=multiquery,
125126
headers=headers,
126127
)
127128

128129
except requests.exceptions.HTTPError as error:
129-
handle_error(error)
130+
error_resp = handle_error(error)
131+
if error_resp and error_resp.get("retry"):
132+
# Retry the request with the new access token
133+
headers["Authorization"] = f"Bearer {get_access_token()}"
134+
response = services.api_request(
135+
Sources.IGDB.value,
136+
"POST",
137+
url,
138+
data=data,
139+
headers=headers,
140+
)
130141

131142
search_results = next(
132143
(item["result"] for item in response if item["name"] == "SearchResults"),

0 commit comments

Comments
 (0)