diff --git a/lib/common/typeorm.utils.ts b/lib/common/typeorm.utils.ts index 35cf557f7..fa99e99be 100644 --- a/lib/common/typeorm.utils.ts +++ b/lib/common/typeorm.utils.ts @@ -110,17 +110,21 @@ export function getEntityManagerToken( export function handleRetry( retryAttempts = 9, retryDelay = 3000, + verboseRetryLog = false, ): (source: Observable) => Observable { return (source: Observable) => source.pipe( - retryWhen(e => + retryWhen((e) => e.pipe( scan((errorCount, error: Error) => { - logger.error( - `Unable to connect to the database. Message: ${error.message}. Retrying (${errorCount + - 1})...`, - error.stack, - ); + const message = verboseRetryLog + ? `Unable to connect to the database. Message: ${ + error.message + }. Retrying (${errorCount + 1})...` + : `Unable to connect to the database. Retrying (${ + errorCount + 1 + })...`; + logger.error(message, error.stack); if (errorCount + 1 >= retryAttempts) { throw error; } diff --git a/lib/interfaces/typeorm-options.interface.ts b/lib/interfaces/typeorm-options.interface.ts index da7438c88..a6575b4ef 100644 --- a/lib/interfaces/typeorm-options.interface.ts +++ b/lib/interfaces/typeorm-options.interface.ts @@ -21,6 +21,10 @@ export type TypeOrmModuleOptions = { * If `true`, connection will not be closed on application shutdown. */ keepConnectionAlive?: boolean; + /** + * If `true`, will show verbose error messages on each connection retry. + */ + verboseRetryLog?: boolean; } & Partial; export interface TypeOrmOptionsFactory { diff --git a/lib/typeorm-core.module.ts b/lib/typeorm-core.module.ts index f8fd66b11..29d191dbb 100644 --- a/lib/typeorm-core.module.ts +++ b/lib/typeorm-core.module.ts @@ -201,7 +201,13 @@ export class TypeOrmCoreModule implements OnApplicationShutdown { entities, } as ConnectionOptions); }) - .pipe(handleRetry(options.retryAttempts, options.retryDelay)) + .pipe( + handleRetry( + options.retryAttempts, + options.retryDelay, + options.verboseRetryLog, + ), + ) .toPromise(); } }