Debug: Agregar logging extensivo en servidor y cliente
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m6s
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:
@@ -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')
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user