mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 23:42:07 +01:00
Attempt to force refresh twitch auth token if 401
This commit is contained in:
@@ -49,9 +49,23 @@ class IGDBHandler:
|
||||
try:
|
||||
res = requests.post(url, data, headers=self.headers, timeout=timeout)
|
||||
res.raise_for_status()
|
||||
return res.json()
|
||||
except (HTTPError, Timeout) as err:
|
||||
if err.response.status_code != 401:
|
||||
log.error(err)
|
||||
return [] # All requests to the IGDB API return a list
|
||||
|
||||
# Attempt to force a token refresh if the token is invalid
|
||||
log.warning("Twitch token invalid: fetching a new one...")
|
||||
token = self.twitch_auth._update_twitch_token()
|
||||
self.headers["Authorization"] = f"Bearer {token}"
|
||||
|
||||
try:
|
||||
res = requests.post(url, data, headers=self.headers, timeout=timeout)
|
||||
res.raise_for_status()
|
||||
except (HTTPError, Timeout) as err:
|
||||
# Log the error and return an empty list if the request fails again
|
||||
log.error(err)
|
||||
# All requests to the IGDB API return a list
|
||||
return []
|
||||
|
||||
return res.json()
|
||||
|
||||
Reference in New Issue
Block a user