mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
feat: Simplify error responses in handle_download_model with consistent JSON format
This commit is contained in:
@@ -567,15 +567,7 @@ class ModelRouteUtils:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def handle_download_model(request: web.Request, download_manager: DownloadManager) -> web.Response:
|
async def handle_download_model(request: web.Request, download_manager: DownloadManager) -> web.Response:
|
||||||
"""Handle model download request
|
"""Handle model download request"""
|
||||||
|
|
||||||
Args:
|
|
||||||
request: The aiohttp request
|
|
||||||
download_manager: Instance of DownloadManager
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
web.Response: The HTTP response
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
|
|
||||||
@@ -594,10 +586,10 @@ class ModelRouteUtils:
|
|||||||
try:
|
try:
|
||||||
model_id = int(data.get('model_id'))
|
model_id = int(data.get('model_id'))
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
return web.Response(
|
return web.json_response({
|
||||||
status=400,
|
'success': False,
|
||||||
text="Invalid model_id: Must be an integer"
|
'error': "Invalid model_id: Must be an integer"
|
||||||
)
|
}, status=400)
|
||||||
|
|
||||||
# Convert model_version_id to int if provided
|
# Convert model_version_id to int if provided
|
||||||
model_version_id = None
|
model_version_id = None
|
||||||
@@ -605,17 +597,17 @@ class ModelRouteUtils:
|
|||||||
try:
|
try:
|
||||||
model_version_id = int(data.get('model_version_id'))
|
model_version_id = int(data.get('model_version_id'))
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
return web.Response(
|
return web.json_response({
|
||||||
status=400,
|
'success': False,
|
||||||
text="Invalid model_version_id: Must be an integer"
|
'error': "Invalid model_version_id: Must be an integer"
|
||||||
)
|
}, status=400)
|
||||||
|
|
||||||
# Only model_id is required, model_version_id is optional
|
# Only model_id is required, model_version_id is optional
|
||||||
if not model_id:
|
if not model_id:
|
||||||
return web.Response(
|
return web.json_response({
|
||||||
status=400,
|
'success': False,
|
||||||
text="Missing required parameter: Please provide 'model_id'"
|
'error': "Missing required parameter: Please provide 'model_id'"
|
||||||
)
|
}, status=400)
|
||||||
|
|
||||||
use_default_paths = data.get('use_default_paths', False)
|
use_default_paths = data.get('use_default_paths', False)
|
||||||
|
|
||||||
@@ -637,12 +629,15 @@ class ModelRouteUtils:
|
|||||||
# Return 401 for early access errors
|
# Return 401 for early access errors
|
||||||
if 'early access' in error_message.lower():
|
if 'early access' in error_message.lower():
|
||||||
logger.warning(f"Early access download failed: {error_message}")
|
logger.warning(f"Early access download failed: {error_message}")
|
||||||
return web.Response(
|
return web.json_response({
|
||||||
status=401, # Use 401 status code to match Civitai's response
|
'success': False,
|
||||||
text=f"Early Access Restriction: {error_message}"
|
'error': f"Early Access Restriction: {error_message}"
|
||||||
)
|
}, status=401)
|
||||||
|
|
||||||
return web.Response(status=500, text=error_message)
|
return web.json_response({
|
||||||
|
'success': False,
|
||||||
|
'error': error_message
|
||||||
|
}, status=500)
|
||||||
|
|
||||||
return web.json_response(result)
|
return web.json_response(result)
|
||||||
|
|
||||||
@@ -652,13 +647,16 @@ class ModelRouteUtils:
|
|||||||
# Check if this might be an early access error
|
# Check if this might be an early access error
|
||||||
if '401' in error_message:
|
if '401' in error_message:
|
||||||
logger.warning(f"Early access error (401): {error_message}")
|
logger.warning(f"Early access error (401): {error_message}")
|
||||||
return web.Response(
|
return web.json_response({
|
||||||
status=401,
|
'success': False,
|
||||||
text="Early Access Restriction: This model requires purchase. Please buy early access on Civitai.com."
|
'error': "Early Access Restriction: This model requires purchase. Please buy early access on Civitai.com."
|
||||||
)
|
}, status=401)
|
||||||
|
|
||||||
logger.error(f"Error downloading model: {error_message}")
|
logger.error(f"Error downloading model: {error_message}")
|
||||||
return web.Response(status=500, text=error_message)
|
return web.json_response({
|
||||||
|
'success': False,
|
||||||
|
'error': error_message
|
||||||
|
}, status=500)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def handle_bulk_delete_models(request: web.Request, scanner) -> web.Response:
|
async def handle_bulk_delete_models(request: web.Request, scanner) -> web.Response:
|
||||||
|
|||||||
Reference in New Issue
Block a user