From a37c1bb7d65ec9a2bd92f0079571e0ce92edd23f Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Fri, 24 Jul 2026 10:34:55 -0500 Subject: [PATCH] fix: _parse_tns_resp distingue status booleano (TNS) de entero HTTP (ASP.NET) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/routes/automation.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/routes/automation.py b/app/routes/automation.py index 031bb1e..d6fa572 100644 --- a/app/routes/automation.py +++ b/app/routes/automation.py @@ -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]