mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
Enhance CivitaiClient error handling for unauthorized access
- Updated handling of 401 unauthorized responses to differentiate between API key issues and early access restrictions. - Improved logging for unauthorized access attempts. - Refactored condition to check for early access restrictions based on response headers. - Adjusted logic in DownloadManager to check for early access using a more concise method.
This commit is contained in:
@@ -76,9 +76,15 @@ class CivitaiClient:
|
|||||||
headers = self._get_request_headers()
|
headers = self._get_request_headers()
|
||||||
async with session.get(url, headers=headers, allow_redirects=True) as response:
|
async with session.get(url, headers=headers, allow_redirects=True) as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
# Handle early access 401 unauthorized responses
|
# Handle 401 unauthorized responses
|
||||||
if response.status == 401:
|
if response.status == 401:
|
||||||
logger.warning(f"Unauthorized access to resource: {url} (Status 401)")
|
logger.warning(f"Unauthorized access to resource: {url} (Status 401)")
|
||||||
|
|
||||||
|
# Check if this is an API key issue (has Set-Cookie headers)
|
||||||
|
if 'Set-Cookie' in response.headers:
|
||||||
|
return False, "Invalid or missing CivitAI API key. Please check your API key in settings."
|
||||||
|
|
||||||
|
# Otherwise it's an early access restriction
|
||||||
return False, "Early access restriction: You must purchase early access to download this LoRA."
|
return False, "Early access restriction: You must purchase early access to download this LoRA."
|
||||||
|
|
||||||
# Handle other client errors that might be permission-related
|
# Handle other client errors that might be permission-related
|
||||||
@@ -251,4 +257,4 @@ class CivitaiClient:
|
|||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error getting hash from Civitai: {e}")
|
logger.error(f"Error getting hash from Civitai: {e}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class DownloadManager:
|
|||||||
return {'success': False, 'error': 'Failed to fetch model metadata'}
|
return {'success': False, 'error': 'Failed to fetch model metadata'}
|
||||||
|
|
||||||
# Check if this is an early access LoRA
|
# Check if this is an early access LoRA
|
||||||
if 'earlyAccessEndsAt' in version_info:
|
if version_info.get('earlyAccessEndsAt'):
|
||||||
early_access_date = version_info.get('earlyAccessEndsAt', '')
|
early_access_date = version_info.get('earlyAccessEndsAt', '')
|
||||||
# Convert to a readable date if possible
|
# Convert to a readable date if possible
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user