From 30a4b9fd1f6bcee388576f5bcf30ef9f6a7e2e7c Mon Sep 17 00:00:00 2001 From: Mahdi Chaari Date: Thu, 21 Mar 2024 22:52:21 +0100 Subject: [PATCH 1/4] refactor: Handle optional transporter.verify gracefully --- lib/mailer.service.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/mailer.service.ts b/lib/mailer.service.ts index 74aff39d..c2625a03 100644 --- a/lib/mailer.service.ts +++ b/lib/mailer.service.ts @@ -105,9 +105,10 @@ export class MailerService { private verifyTransporter(transporter: Transporter, name?: string): void { const transporterName = name ? ` '${name}'` : ''; - transporter.verify() - .then(() => this.mailerLogger.debug(`Transporter${transporterName} is ready`)) - .catch((error) => this.mailerLogger.error(`Error occurred while verifying the transporter${transporterName}: ${error.message}`)); + !transporter.verify ? this.mailerLogger.debug(`Transporter${transporterName} is ready`) : + transporter.verify() + .then(() => this.mailerLogger.debug(`Transporter${transporterName} is ready`)) + .catch((error) => this.mailerLogger.error(`Error occurred while verifying the transporter${transporterName}: ${error.message}`)); } public async verifyAllTransporters() { From 769a94dac73827f155af51beb273cb841a61c7a4 Mon Sep 17 00:00:00 2001 From: Mahdi Chaari Date: Fri, 22 Mar 2024 11:26:13 +0100 Subject: [PATCH 2/4] Update mailer.service.ts --- lib/mailer.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mailer.service.ts b/lib/mailer.service.ts index c2625a03..0128b494 100644 --- a/lib/mailer.service.ts +++ b/lib/mailer.service.ts @@ -105,10 +105,10 @@ export class MailerService { private verifyTransporter(transporter: Transporter, name?: string): void { const transporterName = name ? ` '${name}'` : ''; - !transporter.verify ? this.mailerLogger.debug(`Transporter${transporterName} is ready`) : - transporter.verify() - .then(() => this.mailerLogger.debug(`Transporter${transporterName} is ready`)) - .catch((error) => this.mailerLogger.error(`Error occurred while verifying the transporter${transporterName}: ${error.message}`)); + + transporter.verify() + .?then(() => this.mailerLogger.debug(`Transporter${transporterName} is ready`)) + .?catch((error) => this.mailerLogger.error(`Error occurred while verifying the transporter${transporterName}: ${error.message}`)); } public async verifyAllTransporters() { From 3dcd89ca363ea6998967ea3836a2d00c75d12053 Mon Sep 17 00:00:00 2001 From: Mahdi Chaari Date: Fri, 22 Mar 2024 11:31:35 +0100 Subject: [PATCH 3/4] Update mailer.service.ts --- lib/mailer.service.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/mailer.service.ts b/lib/mailer.service.ts index 0128b494..d2bca730 100644 --- a/lib/mailer.service.ts +++ b/lib/mailer.service.ts @@ -105,10 +105,11 @@ export class MailerService { private verifyTransporter(transporter: Transporter, name?: string): void { const transporterName = name ? ` '${name}'` : ''; - - transporter.verify() - .?then(() => this.mailerLogger.debug(`Transporter${transporterName} is ready`)) - .?catch((error) => this.mailerLogger.error(`Error occurred while verifying the transporter${transporterName}: ${error.message}`)); + + // wrap value in a promise to ensure then is always defined + new Promise(()=>transporter?.verify()) + ?.then(() => this.mailerLogger.log(`Transporter${transporterName} is ready`)) + ?.catch((error) => this.mailerLogger.log(`Error occurred while verifying the transporter${transporterName}}: ${error.message}`)); } public async verifyAllTransporters() { From 914da9a25b3cd0332daeb8d2659de4c6775784fb Mon Sep 17 00:00:00 2001 From: Mahdi Chaari Date: Fri, 22 Mar 2024 11:32:10 +0100 Subject: [PATCH 4/4] Update mailer.service.ts --- lib/mailer.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mailer.service.ts b/lib/mailer.service.ts index d2bca730..de3e2136 100644 --- a/lib/mailer.service.ts +++ b/lib/mailer.service.ts @@ -108,8 +108,8 @@ export class MailerService { // wrap value in a promise to ensure then is always defined new Promise(()=>transporter?.verify()) - ?.then(() => this.mailerLogger.log(`Transporter${transporterName} is ready`)) - ?.catch((error) => this.mailerLogger.log(`Error occurred while verifying the transporter${transporterName}}: ${error.message}`)); + .then(() => this.mailerLogger.log(`Transporter${transporterName} is ready`)) + .catch((error) => this.mailerLogger.log(`Error occurred while verifying the transporter${transporterName}}: ${error.message}`)); } public async verifyAllTransporters() {