Skip to content

Commit 12b6c30

Browse files
committed
fix(CursorResponse): enhance id getter to handle missing cursor id
- Updated the id getter to throw an error if the cursor id is missing, ensuring more robust error handling. - Adjusted the retrieval of cursor id to return 0 when it is null, improving the reliability of cursor operations. - This change aims to enhance the accuracy of responses by enforcing the presence of a valid cursor id.
1 parent 324e793 commit 12b6c30

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cmap/wire_protocol/responses.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,15 @@ export class CursorResponse extends MongoDBResponse {
248248

249249
public get id(): Long {
250250
try {
251-
const cursorId = this.cursor.get('id', BSONType.long, true);
252-
return Long.fromBigInt(cursorId);
251+
if (!this.cursor.has('id')) {
252+
throw new MongoUnexpectedServerResponseError('"id" is missing');
253+
}
254+
const cursorId = this.cursor.get('id', BSONType.long, false);
255+
return cursorId != null ? Long.fromBigInt(cursorId) : Long.fromBigInt(0n);
253256
} catch (cause) {
257+
if (cause instanceof MongoUnexpectedServerResponseError) {
258+
throw cause;
259+
}
254260
throw new MongoUnexpectedServerResponseError(cause.message, { cause });
255261
}
256262
}

0 commit comments

Comments
 (0)