Skip to content

Commit

Permalink
refactor(typeorm): improve mongodb checker
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Nov 26, 2023
1 parent 063b25a commit 2ee6d5a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/health-indicator/database/typeorm.health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,22 @@ export class TypeOrmHealthIndicator extends HealthIndicator {

private async checkMongoDBConnection(connection: any) {
return new Promise<void>((resolve, reject) => {
const driver = connection.driver as any;
// Hacky workaround which uses the native MongoClient
const driver = connection.driver;
const url = connection.options.url
? connection.options.url
: driver.buildConnectionUrl(connection.options);

// FIXME: Hacky workaround which uses the native MongoClient
driver.mongodb.MongoClient.connect(
connection.options.url
? connection.options.url
: driver.buildConnectionUrl(connection.options),
url,
driver.buildConnectionOptions(connection.options),
)
.catch((err: Error) => reject(new MongoConnectionError(err.message)))
.then((client: TypeOrm.MongoClient) => client.close().catch(() => {}))
.then((client: TypeOrm.MongoClient) => client.close())

// Noop when trying to close a closed connection
// eslint-disable-next-line @typescript-eslint/no-empty-function
.catch(() => {})
.then(() => resolve());
});
}
Expand Down

0 comments on commit 2ee6d5a

Please sign in to comment.