fix(image-gen): preserve xAI API error status

This commit is contained in:
Cameron Aragon 2026-04-30 01:23:57 +00:00 committed by Teknium
parent 75b4a34670
commit 239ea1bdea
2 changed files with 25 additions and 3 deletions

View file

@ -203,11 +203,12 @@ class XAIImageGenProvider(ImageGenProvider):
)
response.raise_for_status()
except requests.HTTPError as exc:
status = exc.response.status_code if exc.response else 0
response = exc.response
status = response.status_code if response is not None else 0
try:
err_msg = exc.response.json().get("error", {}).get("message", exc.response.text[:300])
err_msg = response.json().get("error", {}).get("message", response.text[:300])
except Exception:
err_msg = exc.response.text[:300] if exc.response else str(exc)
err_msg = response.text[:300] if response is not None else str(exc)
logger.error("xAI image gen failed (%d): %s", status, err_msg)
return error_response(
error=f"xAI image generation failed ({status}): {err_msg}",