fix(widget): deja de mostrar los errores del servidor como respuestas del bot
El widget hacía `data.respuesta || data.message` sin mirar el status, así que un 403/404/500 se pintaba en una burbuja como si lo hubiera dicho el agente. Imposible distinguir "el bot contestó raro" de "el widget está siendo rechazado", que es justo el lazo en el que se puede quedar alguien diagnosticando esto. Además los rechazos del middleware ocurren ANTES del motor, así que no dejaban rastro en ningún lado: ni en la auditoría del agente ni en el navegador. De ahí el síntoma "el chat de prueba anda pero el widget no". - El widget mira r.ok, manda el motivo real a la consola y al visitante le muestra un mensaje neutro. - AuthUmindWidget distingue las tres causas que el chat de prueba NO tiene (agente inactivo, tenant inactivo, dominio no autorizado) y las registra en la auditoría del agente con el detalle accionable — incluyendo qué dominio llamó y cuáles están permitidos. - GetUmindAgentePorSiteKey busca sin filtrar por activo, para poder decir "está apagado" en vez de "no existe". - Test del allowlist de dominios: es fail-closed y www.ejemplo.com NO matchea ejemplo.com, la causa más probable de este síntoma. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
d8f9acd1f8
commit
4995c5fca5
@@ -200,17 +200,37 @@ const umindWidgetJS = `(function () {
|
||||
msgsEl.scrollTop = msgsEl.scrollHeight;
|
||||
}
|
||||
|
||||
// El servidor responde los errores como {"error":true,"message":"..."} con
|
||||
// un status 4xx/5xx. Antes esto se leía igual que una respuesta buena y el
|
||||
// texto del error terminaba en una burbuja, como si lo hubiera dicho el
|
||||
// agente: imposible distinguir "el bot contestó raro" de "el widget está
|
||||
// rechazado". Ahora el motivo real va a la consola y al visitante se le
|
||||
// muestra un mensaje neutro.
|
||||
function leerRespuesta(r) {
|
||||
return r.json().catch(function () { return {}; }).then(function (data) {
|
||||
if (!r.ok || data.error) {
|
||||
var motivo = data.message || ('HTTP ' + r.status);
|
||||
console.error('[uMind] el asistente no pudo responder:', motivo,
|
||||
'— revisá la pestaña Auditoría del agente en uMind Studio.');
|
||||
var e = new Error(motivo);
|
||||
e.esDelServidor = true;
|
||||
throw e;
|
||||
}
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
function iniciar() {
|
||||
sessionId = sessionStorage.getItem(storageKey) || null;
|
||||
fetch(apiBase + '/init')
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(leerRespuesta)
|
||||
.then(function (data) {
|
||||
if (!sessionId) { sessionId = data.session_id; sessionStorage.setItem(storageKey, sessionId); }
|
||||
if (data.nombre) panel.querySelector('#umind-title').textContent = data.nombre;
|
||||
aplicarColor(data.color);
|
||||
agregarMensaje(data.mensaje_bienvenida, 'bot');
|
||||
})
|
||||
.catch(function () { agregarMensaje('No se pudo conectar el asistente.', 'bot'); });
|
||||
.catch(function () { agregarMensaje('El asistente no está disponible en este momento.', 'bot'); });
|
||||
}
|
||||
iniciar(); // arranca ya, así el color/nombre reales están listos antes del primer click
|
||||
|
||||
@@ -224,12 +244,18 @@ const umindWidgetJS = `(function () {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ session_id: sessionId, mensaje: texto })
|
||||
})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(leerRespuesta)
|
||||
.then(function (data) {
|
||||
if (data.session_id) { sessionId = data.session_id; sessionStorage.setItem(storageKey, sessionId); }
|
||||
agregarMensaje(data.respuesta || data.message || 'No pude responder eso.', 'bot');
|
||||
agregarMensaje(data.respuesta || 'No pude responder eso.', 'bot');
|
||||
})
|
||||
.catch(function () { agregarMensaje('Error de conexión, intenta de nuevo.', 'bot'); });
|
||||
.catch(function (e) {
|
||||
agregarMensaje(
|
||||
e && e.esDelServidor
|
||||
? 'El asistente no está disponible en este momento.'
|
||||
: 'Error de conexión, intenta de nuevo.',
|
||||
'bot');
|
||||
});
|
||||
}
|
||||
|
||||
function alternar() {
|
||||
|
||||
Reference in New Issue
Block a user