fix: capture raw PHP response on JSON error in sync-diagnosticos

This commit is contained in:
Lizandro Guarnizo
2026-07-17 10:43:07 -05:00
parent 9a7e4e219b
commit 97f4561283
+12 -1
View File
@@ -83,13 +83,24 @@ async def erp_sync_diagnosticos(user: dict = Depends(get_current_user)):
lote = diagnosticos[i:i + batch_size]
try:
resp = await client.post(url, json={"rows": lote}, headers=headers)
data = resp.json()
try:
data = resp.json()
except Exception:
raw = resp.text[:400].strip()
errores.append(f"Lote {i}-{i+len(lote)} HTTP {resp.status_code}: {raw!r}")
if i == 0:
break # Si el primer lote ya falla, no tiene sentido continuar
continue
if data.get("ok"):
insertados += data.get("insertados", len(lote))
else:
errores.append(f"Lote {i}-{i+len(lote)}: {data.get('error', '?')}")
if i == 0:
break
except Exception as ex:
errores.append(f"Lote {i}-{i+len(lote)}: {ex}")
if i == 0:
break
return JSONResponse({
"ok": len(errores) == 0,