Handle any GET response format gracefully
This commit is contained in:
+13
-3
@@ -555,11 +555,21 @@
|
|||||||
try {
|
try {
|
||||||
const res = await fetch('https://n8n.odoo4projects.com/webhook/odoo-expertos');
|
const res = await fetch('https://n8n.odoo4projects.com/webhook/odoo-expertos');
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
// Response is [{ data: [...] }]
|
// Response can be either:
|
||||||
allExperts = (data[0] && data[0].data) || [];
|
// [{ data: [...] }] - proper expert list
|
||||||
|
// { headers: {...}, body: {}, ... } - webhook metadata (not configured yet)
|
||||||
|
// or other format
|
||||||
|
if (Array.isArray(data) && data[0] && Array.isArray(data[0].data)) {
|
||||||
|
allExperts = data[0].data;
|
||||||
|
} else if (Array.isArray(data) && data.length > 0) {
|
||||||
|
allExperts = data;
|
||||||
|
} else {
|
||||||
|
allExperts = [];
|
||||||
|
}
|
||||||
renderExperts(allExperts);
|
renderExperts(allExperts);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
document.getElementById('expertGridLoading').innerHTML = '<p style="color:#ef4444;">Error al cargar expertos. Intenta de nuevo más tarde.</p>';
|
document.getElementById('expertGridLoading').innerHTML =
|
||||||
|
'<p style="color:#64748b;font-size:0.9375rem;">El mercado de expertos se está cargando. Vuelve a intentarlo en unos momentos.</p>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user