debug: agregar manejo de errores individual para cada query del panorama
This commit is contained in:
@@ -60,7 +60,24 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
]
|
||||
|
||||
// Execute all queries in parallel
|
||||
// Execute all queries in parallel with error handling
|
||||
const executeWithErrorHandling = async (name: string, cardId: number | undefined, defaultValue: any) => {
|
||||
if (!cardId) {
|
||||
console.warn(`[Panorama] No card ID for ${name}`)
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`[Panorama] Executing query: ${name} (ID: ${cardId})`)
|
||||
const result = await executeCardQuery(cardId, parameters)
|
||||
console.log(`[Panorama] Query ${name} returned ${result.data?.rows?.length || 0} rows`)
|
||||
return result
|
||||
} catch (error: any) {
|
||||
console.error(`[Panorama] Error executing ${name}:`, error.message)
|
||||
return defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
const [
|
||||
financieros,
|
||||
ingresoCompra,
|
||||
@@ -72,33 +89,15 @@ export default defineEventHandler(async (event) => {
|
||||
topClientes,
|
||||
conteos
|
||||
] = await Promise.all([
|
||||
cards['panorama_totales_financieros_principales']
|
||||
? executeCardQuery(cards['panorama_totales_financieros_principales'].id, parameters)
|
||||
: { data: { rows: [[0, 0, 0]] } },
|
||||
cards['panorama_totales_ingreso_compra']
|
||||
? executeCardQuery(cards['panorama_totales_ingreso_compra'].id, parameters)
|
||||
: { data: { rows: [[]] } },
|
||||
cards['panorama_totales_monetarios']
|
||||
? executeCardQuery(cards['panorama_totales_monetarios'].id, parameters)
|
||||
: { data: { rows: [[]] } },
|
||||
cards['panorama_totales_verde']
|
||||
? executeCardQuery(cards['panorama_totales_verde'].id, parameters)
|
||||
: { data: { rows: [[]] } },
|
||||
cards['panorama_secos_vendidos']
|
||||
? executeCardQuery(cards['panorama_secos_vendidos'].id, parameters)
|
||||
: { data: { rows: [[]] } },
|
||||
cards['panorama_rechazos_subproductos']
|
||||
? executeCardQuery(cards['panorama_rechazos_subproductos'].id, parameters)
|
||||
: { data: { rows: [] } },
|
||||
cards['panorama_serie_temporal_diaria']
|
||||
? executeCardQuery(cards['panorama_serie_temporal_diaria'].id, parameters)
|
||||
: { data: { rows: [] } },
|
||||
cards['panorama_top_clientes']
|
||||
? executeCardQuery(cards['panorama_top_clientes'].id, parameters)
|
||||
: { data: { rows: [] } },
|
||||
cards['panorama_conteo_registros']
|
||||
? executeCardQuery(cards['panorama_conteo_registros'].id, parameters)
|
||||
: { data: { rows: [[0, 0, 0, 0]] } }
|
||||
executeWithErrorHandling('financieros', cards['panorama_totales_financieros_principales']?.id, { data: { rows: [[0, 0, 0]], cols: [] } }),
|
||||
executeWithErrorHandling('ingresoCompra', cards['panorama_totales_ingreso_compra']?.id, { data: { rows: [[]], cols: [] } }),
|
||||
executeWithErrorHandling('monetarios', cards['panorama_totales_monetarios']?.id, { data: { rows: [[]], cols: [] } }),
|
||||
executeWithErrorHandling('verde', cards['panorama_totales_verde']?.id, { data: { rows: [[]], cols: [] } }),
|
||||
executeWithErrorHandling('secosVendidos', cards['panorama_secos_vendidos']?.id, { data: { rows: [[]], cols: [] } }),
|
||||
executeWithErrorHandling('rechazos', cards['panorama_rechazos_subproductos']?.id, { data: { rows: [], cols: [] } }),
|
||||
executeWithErrorHandling('serieTemporal', cards['panorama_serie_temporal_diaria']?.id, { data: { rows: [], cols: [] } }),
|
||||
executeWithErrorHandling('topClientes', cards['panorama_top_clientes']?.id, { data: { rows: [], cols: [] } }),
|
||||
executeWithErrorHandling('conteos', cards['panorama_conteo_registros']?.id, { data: { rows: [[0, 0, 0, 0]], cols: [] } })
|
||||
])
|
||||
|
||||
// Transform Metabase responses to objects for easier frontend consumption
|
||||
|
||||
Reference in New Issue
Block a user