fix: _parse_tns_resp distingue status booleano (TNS) de entero HTTP (ASP.NET)
bool(400) era True en Python, haciendo que errores de validación de ASP.NET
(status:400, errors:{campo:[msg]}) se guardaran como success. Ahora:
- status bool → ok directamente
- status int → ok si < 400
- errors dict → mensaje legible "campo: mensaje"
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2525e053bf
commit
a37c1bb7d6
@@ -793,8 +793,21 @@ def _parse_tns_resp(resp) -> tuple[bool, str]:
|
||||
"""Parsea respuesta TNS: retorna (ok, msg). Trata 'ya existe' como OK."""
|
||||
try:
|
||||
body = resp.json()
|
||||
ok = bool(body.get("status")) or bool((body.get("data") or {}).get("success"))
|
||||
msg = body.get("message") or (body.get("data") or {}).get("response") or resp.text[:200]
|
||||
raw_status = body.get("status")
|
||||
# TNS usa status=true/false (booleano); ASP.NET usa status=400 (entero HTTP) → error
|
||||
if isinstance(raw_status, bool):
|
||||
ok = raw_status
|
||||
elif isinstance(raw_status, int):
|
||||
ok = raw_status < 400
|
||||
else:
|
||||
ok = bool(raw_status) or bool((body.get("data") or {}).get("success"))
|
||||
# Mensaje: TNS normal vs error de validación ASP.NET
|
||||
errors = body.get("errors")
|
||||
if errors and isinstance(errors, dict):
|
||||
msgs = [f"{k}: {v[0] if isinstance(v, list) else v}" for k, v in errors.items()]
|
||||
msg = " | ".join(msgs)
|
||||
else:
|
||||
msg = body.get("message") or (body.get("data") or {}).get("response") or body.get("title") or resp.text[:200]
|
||||
except Exception:
|
||||
ok = resp.is_success
|
||||
msg = resp.text[:200]
|
||||
|
||||
Reference in New Issue
Block a user