Skip to content

Commit 8c2ed05

Browse files
mbroadstdaprahamian
authored andcommitted
refactor: improve robustness of ReadConcern.fromOptions
We made some assumptions in this method about the existence of keys, as well as that no `readConcern` passed in would ever already be of the type we were looking to cast to.
1 parent 5ae9928 commit 8c2ed05

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/read_concern.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ class ReadConcern {
2929
}
3030

3131
if (options.readConcern) {
32+
if (options.readConcern instanceof ReadConcern) {
33+
return options.readConcern;
34+
}
35+
3236
return new ReadConcern(options.readConcern.level);
3337
}
3438

35-
return new ReadConcern(options.level);
39+
if (options.level) {
40+
return new ReadConcern(options.level);
41+
}
3642
}
3743

3844
static get MAJORITY() {

0 commit comments

Comments
 (0)