diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index 392afa17..21b528be 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -227,11 +227,16 @@ export class BaileysStartupService extends ChannelStartupService { this.client?.ws?.close(); - await this.prismaRepository.session.delete({ - where: { - sessionId: this.instanceId, - }, + const sessionExists = await this.prismaRepository.session.findFirst({ + where: { sessionId: this.instanceId }, }); + if (sessionExists) { + await this.prismaRepository.session.delete({ + where: { + sessionId: this.instanceId, + }, + }); + } } public async getProfileName() {