File tree 1 file changed +11
-5
lines changed
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change
1
+ import makeDebug from "debug" ;
1
2
import { MongoClient } from "mongodb" ;
2
3
4
+ const debug = makeDebug ( `indiekit:mongodb` ) ;
5
+
3
6
/**
4
7
* Connect to MongoDB client
5
8
* @param {string } mongodbUrl - MongoDB URL
@@ -12,23 +15,26 @@ export const getMongodbClient = async (mongodbUrl) => {
12
15
return ;
13
16
}
14
17
15
- // Create client
18
+ const connectTimeoutMS = 5000 ;
16
19
try {
20
+ debug ( `try creating MongoDB client` ) ;
17
21
client = new MongoClient ( mongodbUrl , {
18
- connectTimeoutMS : 5000 ,
22
+ connectTimeoutMS,
19
23
} ) ;
20
24
} catch ( error ) {
25
+ debug (
26
+ `could not create MongoDB client with ${ connectTimeoutMS } ms: ${ error . message } ` ,
27
+ ) ;
21
28
console . error ( error . message ) ;
22
-
23
29
return { error } ;
24
30
}
25
31
26
- // Connect to client
27
32
try {
33
+ debug ( `try connecting to MongoDB client` ) ;
28
34
await client . connect ( ) ;
29
35
} catch ( error ) {
36
+ debug ( `could not connect to MongoDB client: ${ error . message } ` ) ;
30
37
console . error ( error . message ) ;
31
-
32
38
await client . close ( ) ;
33
39
return { error } ;
34
40
}
You can’t perform that action at this time.
0 commit comments