File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -22,20 +22,22 @@ export abstract class MongoDBToolBase extends ToolBase {
22
22
) ;
23
23
}
24
24
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
+ }
27
36
}
37
+ }
28
38
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" ) ;
39
41
}
40
42
41
43
return this . session . serviceProvider ! ;
You can’t perform that action at this time.
0 commit comments