fix(cli): initialize mailer just if connection can be verified (#3997)

This commit is contained in:
Ben Hesseldieck 2022-09-01 14:57:14 +02:00 committed by GitHub
parent d82e87979d
commit 936cb11789
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<UserManagementMailer> {
if (mailerInstance === undefined) {
mailerInstance = new UserManagementMailer();
await mailerInstance.verifyConnection();
try {
await mailerInstance.verifyConnection();
} catch (error) {
mailerInstance = undefined;
throw error;
}
}
return mailerInstance;
}