mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
fix: Add better error handling for litellm model prices fetch
- Add content-type check for JSON response - Add proper error handling for all exceptions - Add clear error messages using click.secho - Return None on any error condition Fixes #2116 Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -166,6 +166,12 @@ def fetch_provider_data(cache_file):
|
||||
try:
|
||||
response = requests.get(JSON_URL, stream=True, timeout=60)
|
||||
response.raise_for_status()
|
||||
|
||||
# Add content-type check
|
||||
if not response.headers.get('content-type', '').startswith('application/json'):
|
||||
click.secho("Error: Expected JSON response but got different content type", fg="red")
|
||||
return None
|
||||
|
||||
data = download_data(response)
|
||||
with open(cache_file, "w") as f:
|
||||
json.dump(data, f)
|
||||
@@ -174,6 +180,8 @@ def fetch_provider_data(cache_file):
|
||||
click.secho(f"Error fetching provider data: {e}", fg="red")
|
||||
except json.JSONDecodeError:
|
||||
click.secho("Error parsing provider data. Invalid JSON format.", fg="red")
|
||||
except Exception as e:
|
||||
click.secho(f"Unexpected error fetching provider data: {e}", fg="red")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user