refactor: update reconnection logic to prevent reconnection in cases of banishment or blocking

Handled specific errors to improve reconnection logic:
- 401: Triggered logout to handle unauthorized access.
- 402: Recognized as temporary ban, reconnection attempts paused.
- 403: Recognized as forbidden, reconnection attempts stopped.
- 406: Recognized as permanent ban, reconnection attempts halted.
This commit is contained in:
Felipe Medeiros 2024-08-06 01:48:42 -03:00
parent d82945a735
commit 258f56759c

View File

@ -388,7 +388,9 @@ export class BaileysStartupService extends ChannelStartupService {
}
if (connection === 'close') {
const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut;
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
const shouldReconnect = !codesToNotReconnect.includes(statusCode);
if (shouldReconnect) {
await this.connectToWhatsapp(this.phoneNumber);
} else {