Skip to content

Commit 0a1e57c

Browse files
committed
fix: tests
1 parent 1127f4c commit 0a1e57c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/tools/mongodb/mongodbTool.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ export abstract class MongoDBToolBase extends ToolBase {
2222
);
2323
}
2424

25-
if (!this.config.connectionString) {
26-
throw new MongoDBError(ErrorCodes.NotConnectedToMongoDB, "Not connected to MongoDB");
25+
if (this.config.connectionString) {
26+
try {
27+
await this.connectToMongoDB(this.config.connectionString);
28+
} catch (error) {
29+
logger.error(
30+
LogId.mongodbConnectFailure,
31+
"mongodbTool",
32+
`Failed to connect to MongoDB instance using the connection string from the config: ${error as string}`
33+
);
34+
throw new MongoDBError(ErrorCodes.MisconfiguredConnectionString, "Not connected to MongoDB.");
35+
}
2736
}
37+
}
2838

29-
try {
30-
await this.connectToMongoDB(this.config.connectionString);
31-
} catch (error) {
32-
logger.error(
33-
LogId.mongodbConnectFailure,
34-
"mongodbTool",
35-
`Failed to connect to MongoDB instance using the connection string from the config: ${error as string}`
36-
);
37-
throw new MongoDBError(ErrorCodes.MisconfiguredConnectionString, "Not connected to MongoDB.");
38-
}
39+
if (!this.session.serviceProvider) {
40+
throw new MongoDBError(ErrorCodes.NotConnectedToMongoDB, "Not connected to MongoDB");
3941
}
4042

4143
return this.session.serviceProvider!;

0 commit comments

Comments
 (0)