fix: improve TMDB timeout handling and increase timeout to 60s
- Increase request timeout from 30s to 60s for slower TMDB responses - Add explicit asyncio.TimeoutError handling with retry logic - Separate timeout error handling from general ClientError handling - Provides better logging for timeout vs other failures
This commit is contained in:
@@ -122,7 +122,7 @@ class TMDBClient:
|
||||
raise TMDBAPIError("Session is not available")
|
||||
|
||||
logger.debug(f"TMDB API request: {endpoint} (attempt {attempt + 1})")
|
||||
async with self.session.get(url, params=params, timeout=aiohttp.ClientTimeout(total=30)) as resp:
|
||||
async with self.session.get(url, params=params, timeout=aiohttp.ClientTimeout(total=60)) as resp:
|
||||
if resp.status == 401:
|
||||
raise TMDBAPIError("Invalid TMDB API key")
|
||||
elif resp.status == 404:
|
||||
@@ -139,6 +139,15 @@ class TMDBClient:
|
||||
self._cache[cache_key] = data
|
||||
return data
|
||||
|
||||
except asyncio.TimeoutError as e:
|
||||
last_error = e
|
||||
if attempt < max_retries - 1:
|
||||
logger.warning(f"Request timeout (attempt {attempt + 1}), retrying in {delay}s")
|
||||
await asyncio.sleep(delay)
|
||||
delay *= 2
|
||||
else:
|
||||
logger.error(f"Request timed out after {max_retries} attempts")
|
||||
|
||||
except (aiohttp.ClientError, AttributeError) as e:
|
||||
last_error = e
|
||||
# If connector/session was closed, try to recreate it
|
||||
|
||||
Reference in New Issue
Block a user