Debug: Agregar logging extensivo en servidor y cliente
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m6s

- 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
This commit is contained in:
2025-11-21 23:39:11 -06:00
parent 2ca062b9e0
commit b0b179d945
2 changed files with 13 additions and 1 deletions

View File

@@ -31,8 +31,10 @@ export interface TrazabilidadRow {
} }
export const useLotes = () => { export const useLotes = () => {
console.log('🔵 useLotes: Composable llamado, process.client:', process.client)
// useToast solo funciona en el cliente, no en SSR // useToast solo funciona en el cliente, no en SSR
const toast = process.client ? useToast() : null const toast = process.client ? useToast() : null
console.log('🔵 useLotes: Toast inicializado:', !!toast)
// ===================================================== // =====================================================
// FUNCIONES PARA LOTES // FUNCIONES PARA LOTES
@@ -46,6 +48,7 @@ export const useLotes = () => {
limit?: number limit?: number
offset?: number offset?: number
}) => { }) => {
console.log('🔵 fetchLotes: Iniciando, filtros:', filtros)
try { try {
const query = new URLSearchParams() const query = new URLSearchParams()
if (filtros?.tipo) query.append('tipo', filtros.tipo) if (filtros?.tipo) query.append('tipo', filtros.tipo)
@@ -54,12 +57,15 @@ export const useLotes = () => {
const queryString = query.toString() const queryString = query.toString()
const url = `/api/lotes${queryString ? `?${queryString}` : ''}` const url = `/api/lotes${queryString ? `?${queryString}` : ''}`
console.log('🔵 fetchLotes: URL construida:', url)
console.log('🔵 fetchLotes: Llamando a useFetch...')
const { data, error } = await useFetch<{ const { data, error } = await useFetch<{
success: boolean success: boolean
data: Lote[] data: Lote[]
count: number count: number
}>(url) }>(url)
console.log('🔵 fetchLotes: useFetch completado, data:', !!data.value, 'error:', !!error.value)
if (error.value) { if (error.value) {
throw new Error(error.value.message || 'Error obteniendo lotes') throw new Error(error.value.message || 'Error obteniendo lotes')

View File

@@ -10,16 +10,21 @@ import { getLotes } from '../../utils/queries'
* - offset: offset para paginación * - offset: offset para paginación
*/ */
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
console.log('🟦 API /api/lotes: Request recibido')
try { try {
const query = getQuery(event) const query = getQuery(event)
console.log('🟦 API /api/lotes: Query params:', query)
const filtros = { const filtros = {
tipo: query.tipo as string | undefined, tipo: query.tipo as string | undefined,
limit: query.limit ? parseInt(query.limit as string) : undefined, limit: query.limit ? parseInt(query.limit as string) : undefined,
offset: query.offset ? parseInt(query.offset 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) const lotes = await getLotes(filtros)
console.log('🟦 API /api/lotes: Lotes obtenidos:', lotes.length)
return { return {
success: true, success: true,
@@ -27,7 +32,8 @@ export default defineEventHandler(async (event) => {
count: lotes.length, count: lotes.length,
} }
} catch (error: any) { } 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({ throw createError({
statusCode: 500, statusCode: 500,
statusMessage: 'Error obteniendo lotes', statusMessage: 'Error obteniendo lotes',