From b0b179d94502466e459548db315ea45498106829 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 21 Nov 2025 23:39:11 -0600 Subject: [PATCH] Debug: Agregar logging extensivo en servidor y cliente MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Logs en useLotes() para ver cuándo se llama - Logs en fetchLotes() para rastrear el flujo - Logs en API /api/lotes para ver requests del servidor - Todos los logs con emojis para fácil identificación: 🔵 = Cliente/Composable 🟦 = Servidor/API ❌ = Errores --- nuxt4/app/composables/useLotes.ts | 6 ++++++ nuxt4/server/api/lotes/index.get.ts | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nuxt4/app/composables/useLotes.ts b/nuxt4/app/composables/useLotes.ts index 2de2aa1..65cc72d 100644 --- a/nuxt4/app/composables/useLotes.ts +++ b/nuxt4/app/composables/useLotes.ts @@ -31,8 +31,10 @@ export interface TrazabilidadRow { } export const useLotes = () => { + console.log('🔵 useLotes: Composable llamado, process.client:', process.client) // useToast solo funciona en el cliente, no en SSR const toast = process.client ? useToast() : null + console.log('🔵 useLotes: Toast inicializado:', !!toast) // ===================================================== // FUNCIONES PARA LOTES @@ -46,6 +48,7 @@ export const useLotes = () => { limit?: number offset?: number }) => { + console.log('🔵 fetchLotes: Iniciando, filtros:', filtros) try { const query = new URLSearchParams() if (filtros?.tipo) query.append('tipo', filtros.tipo) @@ -54,12 +57,15 @@ export const useLotes = () => { const queryString = query.toString() const url = `/api/lotes${queryString ? `?${queryString}` : ''}` + console.log('🔵 fetchLotes: URL construida:', url) + console.log('🔵 fetchLotes: Llamando a useFetch...') const { data, error } = await useFetch<{ success: boolean data: Lote[] count: number }>(url) + console.log('🔵 fetchLotes: useFetch completado, data:', !!data.value, 'error:', !!error.value) if (error.value) { throw new Error(error.value.message || 'Error obteniendo lotes') diff --git a/nuxt4/server/api/lotes/index.get.ts b/nuxt4/server/api/lotes/index.get.ts index 836ca41..25a5839 100644 --- a/nuxt4/server/api/lotes/index.get.ts +++ b/nuxt4/server/api/lotes/index.get.ts @@ -10,16 +10,21 @@ import { getLotes } from '../../utils/queries' * - offset: offset para paginación */ export default defineEventHandler(async (event) => { + console.log('🟦 API /api/lotes: Request recibido') try { const query = getQuery(event) + console.log('🟦 API /api/lotes: Query params:', query) const filtros = { tipo: query.tipo as string | undefined, limit: query.limit ? parseInt(query.limit as string) : undefined, offset: query.offset ? parseInt(query.offset as string) : undefined, } + console.log('🟦 API /api/lotes: Filtros procesados:', filtros) + console.log('🟦 API /api/lotes: Llamando a getLotes...') const lotes = await getLotes(filtros) + console.log('🟦 API /api/lotes: Lotes obtenidos:', lotes.length) return { success: true, @@ -27,7 +32,8 @@ export default defineEventHandler(async (event) => { count: lotes.length, } } catch (error: any) { - console.error('Error obteniendo lotes:', error) + console.error('❌ API /api/lotes: Error:', error.message) + console.error('❌ API /api/lotes: Stack:', error.stack) throw createError({ statusCode: 500, statusMessage: 'Error obteniendo lotes',