Skip to content

Commit 69e7403

Browse files
committed
refactor: apply code review suggestions (safety checks and logging)
1 parent 3d253ff commit 69e7403

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,9 @@ export class BaileysStartupService extends ChannelStartupService {
427427
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
428428
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
429429

430-
// FIX: Não reconectar se é primeira conexão (aguardando QR code)
431-
// Isso evita loop infinito que impede geração do QR
432-
const isInitialConnection = !this.instance.wuid && this.instance.qrcode.count === 0;
430+
// FIX: Do not reconnect if it's the initial connection (waiting for QR code)
431+
// This prevents infinite loop that blocks QR code generation
432+
const isInitialConnection = !this.instance.wuid && (this.instance.qrcode?.count ?? 0) === 0;
433433

434434
if (isInitialConnection) {
435435
this.logger.info('Initial connection closed, waiting for QR code generation...');
@@ -441,6 +441,9 @@ export class BaileysStartupService extends ChannelStartupService {
441441
this.logger.warn(`Connection lost (status: ${statusCode}), reconnecting...`);
442442
await this.connectToWhatsapp(this.phoneNumber);
443443
} else {
444+
this.logger.info(
445+
`Skipping reconnection for status code ${statusCode} (code is in codesToNotReconnect list)`,
446+
);
444447
this.sendDataWebhook(Events.STATUS_INSTANCE, {
445448
instance: this.instance.name,
446449
status: 'closed',

0 commit comments

Comments
 (0)