Skip to content

Commit e9b652f

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 12b6c30 commit e9b652f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/cmap/wire_protocol/responses.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,13 @@ export class CursorResponse extends MongoDBResponse {
247247
}
248248

249249
public get id(): Long {
250+
if (!this.cursor.has('id')) {
251+
throw new MongoUnexpectedServerResponseError('"id" is missing');
252+
}
250253
try {
251-
if (!this.cursor.has('id')) {
252-
throw new MongoUnexpectedServerResponseError('"id" is missing');
253-
}
254254
const cursorId = this.cursor.get('id', BSONType.long, false);
255255
return cursorId != null ? Long.fromBigInt(cursorId) : Long.fromBigInt(0n);
256256
} catch (cause) {
257-
if (cause instanceof MongoUnexpectedServerResponseError) {
258-
throw cause;
259-
}
260257
throw new MongoUnexpectedServerResponseError(cause.message, { cause });
261258
}
262259
}

0 commit comments

Comments
 (0)