From 2500cb1181900d6c6b4349d443605e36137140e7 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Sat, 22 Nov 2025 01:00:30 -0600 Subject: [PATCH] arreglelo plix --- nuxt4/server/utils/db.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nuxt4/server/utils/db.ts b/nuxt4/server/utils/db.ts index 970b193..a31f56f 100644 --- a/nuxt4/server/utils/db.ts +++ b/nuxt4/server/utils/db.ts @@ -63,13 +63,14 @@ export async function query( text: string, params?: any[] ): Promise> { - const pool = getPool() const start = Date.now() const maxRetries = 2 for (let attempt = 0; attempt <= maxRetries; attempt++) { + const currentPool = getPool() + try { - const result = await pool.query(text, params) + const result = await currentPool.query(text, params) const duration = Date.now() - start if (process.env.NODE_ENV !== 'production') { @@ -82,14 +83,14 @@ export async function query( const isConnError = ['ECONNREFUSED', 'ECONNRESET', '57P01'].includes(error?.code) const shouldRetry = attempt < maxRetries && (isAuthError || isConnError) - console.error('Error ejecutando query:', { text, params, error: error?.message, code: error?.code, attempt }) + console.error('Error ejecutando query:', { text, params, error: error?.message || error, code: error?.code, attempt }) if (shouldRetry) { // Pequeño backoff y reintento await new Promise((res) => setTimeout(res, 500 * (attempt + 1))) // Resetear pool en auth/conn error por si la contraseña/estado cambia en caliente try { - await pool.end() + await currentPool.end() } catch (_) {} pool = null continue