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]