Skip to content

Commit 7f0403d

Browse files
committed
fix(): stop app with unexpected error when the connection is not ready
1 parent 55241f2 commit 7f0403d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/typeorm-core.module.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
OnApplicationShutdown,
77
Provider,
88
Type,
9+
Logger,
910
} from '@nestjs/common';
1011
import { ModuleRef } from '@nestjs/core';
1112
import { defer } from 'rxjs';
@@ -33,6 +34,8 @@ import { TYPEORM_MODULE_ID, TYPEORM_MODULE_OPTIONS } from './typeorm.constants';
3334
@Global()
3435
@Module({})
3536
export class TypeOrmCoreModule implements OnApplicationShutdown {
37+
private readonly logger = new Logger('TypeOrmModule');
38+
3639
constructor(
3740
@Inject(TYPEORM_MODULE_OPTIONS)
3841
private readonly options: TypeOrmModuleOptions,
@@ -106,7 +109,11 @@ export class TypeOrmCoreModule implements OnApplicationShutdown {
106109
const connection = this.moduleRef.get<Connection>(
107110
getConnectionToken(this.options as ConnectionOptions) as Type<Connection>,
108111
);
109-
connection && (await connection.close());
112+
try {
113+
connection && (await connection.close());
114+
} catch (e) {
115+
this.logger.error(e.message);
116+
}
110117
}
111118

112119
private static createAsyncProviders(

0 commit comments

Comments
 (0)