Skip to content
Prev Previous commit
Next Next commit
fix: check if the dataSource is initialized before destroying it
  • Loading branch information
Thomas Conner committed May 11, 2022
commit a5e84c154f5f51fc94d0569f73aa0c67b6a9d515
4 changes: 3 additions & 1 deletion lib/typeorm-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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