Improve stems error handling: capture full API error response body
This commit is contained in:
parent
ae9c061225
commit
c676acd32f
1 changed files with 9 additions and 2 deletions
11
helpers.py
11
helpers.py
|
|
@ -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)
|
||||||
data = resp.json()
|
try:
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue