From a5e84c154f5f51fc94d0569f73aa0c67b6a9d515 Mon Sep 17 00:00:00 2001 From: Thomas Conner Date: Wed, 11 May 2022 12:25:23 -0400 Subject: [PATCH] fix: check if the dataSource is initialized before destroying it --- lib/typeorm-core.module.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/typeorm-core.module.ts b/lib/typeorm-core.module.ts index ca39b7c06..009083efd 100644 --- a/lib/typeorm-core.module.ts +++ b/lib/typeorm-core.module.ts @@ -137,7 +137,9 @@ export class TypeOrmCoreModule implements OnApplicationShutdown { getDataSourceToken(this.options as DataSourceOptions) as Type, ); try { - dataSource && (await dataSource.destroy()); + if (dataSource && dataSource.isInitialized) { + await dataSource.destroy(); + } } catch (e) { this.logger.error(e?.message); }