Skip to content
4 changes: 3 additions & 1 deletion lib/typeorm-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export class TypeOrmCoreModule implements OnApplicationShutdown {
getDataSourceToken(this.options as DataSourceOptions) as Type<DataSource>,
);
try {
dataSource && (await dataSource.destroy());
if (dataSource && dataSource.isInitialized) {
await dataSource.destroy();
}
} catch (e) {
this.logger.error(e?.message);
}
Expand Down