Improve stems error handling: capture full API error response body

This commit is contained in:
Troll (Hermes Agent) 2026-08-11 19:20:19 +00:00
parent ae9c061225
commit c676acd32f

View file

@ -624,10 +624,17 @@ def musicgpt_queue_stems(rid, audio_url, stems=None):
} }
try: try:
resp = requests.post(url, data=payload, headers={"Authorization": get_musicgpt_api_key()}, timeout=30) resp = requests.post(url, data=payload, headers={"Authorization": get_musicgpt_api_key()}, timeout=30)
try:
data = resp.json() data = resp.json()
except Exception:
return None, None, None, f"HTTP {resp.status_code}: {resp.text[:300]}"
if resp.status_code == 200 and data.get("success"): if resp.status_code == 200 and data.get("success"):
return data.get("task_id"), data.get("conversion_id"), data.get("credit_estimate"), None return data.get("task_id"), data.get("conversion_id"), data.get("credit_estimate"), None
return None, None, None, data.get("error") or f"HTTP {resp.status_code}" # Capture as much detail as possible from the error response.
error_msg = data.get("error") or data.get("message") or f"HTTP {resp.status_code}"
if data.get("details"):
error_msg += f"{data['details']}"
return None, None, None, error_msg
except Exception as e: except Exception as e:
return None, None, None, str(e) return None, None, None, str(e)