Fix silent failure when loading campaign metrics
carregarMetrics()/carregarMetricsData() swallowed fetch errors with a bare catch, leaving the metrics card blank with no indication anything went wrong (same class of issue already fixed for pending replies). Now shows an explicit error message and toasts. Found via a full-project audit.
This commit is contained in:
+11
-4
@@ -267,10 +267,10 @@ window.campanhasInit = window.campanhasInit || (() => {
|
||||
}
|
||||
|
||||
async function carregarMetrics() {
|
||||
const filters = el('metrics-filters');
|
||||
const display = el('campaign-metrics');
|
||||
try {
|
||||
const campaigns = await API.get('/api/campaigns').then((r) => r.campaigns).catch(() => []);
|
||||
const filters = el('metrics-filters');
|
||||
const display = el('campaign-metrics');
|
||||
|
||||
if (!campaigns.length) {
|
||||
filters.replaceChildren(h('p', { class: 'muted' }, 'Sem campanhas para métricas.'));
|
||||
@@ -297,7 +297,11 @@ window.campanhasInit = window.campanhasInit || (() => {
|
||||
);
|
||||
|
||||
display.replaceChildren(h('p', { class: 'muted' }, 'Selecione uma campanha e clique em "Ver fila" para ver métricas detalhadas.'));
|
||||
} catch { /* silêncio */ }
|
||||
} catch (error) {
|
||||
filters.replaceChildren(h('p', { class: 'muted' }, 'Erro ao carregar métricas.'));
|
||||
display.replaceChildren();
|
||||
toast(`Erro ao carregar métricas: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function carregarMetricsData() {
|
||||
@@ -336,7 +340,10 @@ window.campanhasInit = window.campanhasInit || (() => {
|
||||
: null
|
||||
].filter(Boolean)
|
||||
);
|
||||
} catch { /* silêncio */ }
|
||||
} catch (error) {
|
||||
el('campaign-metrics').replaceChildren(h('p', { class: 'muted' }, 'Erro ao carregar métricas.'));
|
||||
toast(`Erro ao carregar métricas: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Todos os listeners abaixo sao anexados UMA VEZ, aqui, sobre botoes fixos e
|
||||
|
||||
Reference in New Issue
Block a user