From 936cb117895695f9519f0debb3bcac275d98eda8 Mon Sep 17 00:00:00 2001 From: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com> Date: Thu, 1 Sep 2022 14:57:14 +0200 Subject: [PATCH] fix(cli): initialize mailer just if connection can be verified (#3997) --- .../cli/src/UserManagement/email/UserManagementMailer.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/UserManagement/email/UserManagementMailer.ts b/packages/cli/src/UserManagement/email/UserManagementMailer.ts index bf2ef3fd60a45..ad08cd5c3eba2 100644 --- a/packages/cli/src/UserManagement/email/UserManagementMailer.ts +++ b/packages/cli/src/UserManagement/email/UserManagementMailer.ts @@ -1,6 +1,6 @@ -import Handlebars from 'handlebars'; import { existsSync } from 'fs'; import { readFile } from 'fs/promises'; +import Handlebars from 'handlebars'; import { join as pathJoin } from 'path'; // eslint-disable-next-line import/no-cycle import { GenericHelpers } from '../..'; @@ -90,7 +90,12 @@ let mailerInstance: UserManagementMailer | undefined; export async function getInstance(): Promise { if (mailerInstance === undefined) { mailerInstance = new UserManagementMailer(); - await mailerInstance.verifyConnection(); + try { + await mailerInstance.verifyConnection(); + } catch (error) { + mailerInstance = undefined; + throw error; + } } return mailerInstance; }