diff --git a/src/controllers/syncController.js b/src/controllers/syncController.js index 4e2a266..710f3b5 100644 --- a/src/controllers/syncController.js +++ b/src/controllers/syncController.js @@ -76,7 +76,19 @@ const streamEvents = async (req, res) => { }); } catch (error) { - res.status(401).json({ error: 'No autorizado' }); + // šŸ‘‡ ENGAƑAMOS AL CLIENTE SSE PARA QUE NO HAGA RETRY INFINITO + res.setHeader('Content-Type', 'text/event-stream'); + res.setHeader('Cache-Control', 'no-cache'); + res.setHeader('Connection', 'keep-alive'); + res.flushHeaders(); + + // Enviamos un evento personalizado de error + res.write('event: auth_error\n'); + res.write('data: No autorizado\n\n'); + if (typeof res.flush === 'function') res.flush(); + + // Cerramos la conexión amablemente tras medio segundo + setTimeout(() => res.end(), 500); } };