MCPcopy
hub / github.com/mongodb/node-mongodb-native / isErrorResponse

Function isErrorResponse

src/cmap/wire_protocol/responses.ts:42–66  ·  view source on GitHub ↗
(bson: Uint8Array, elements: BSONElement[])

Source from the content-addressed store, hash-verified

40 * @param bytes - BSON document returned from the server
41 */
42export function isErrorResponse(bson: Uint8Array, elements: BSONElement[]): boolean {
43 for (let eIdx = 0; eIdx < elements.length; eIdx++) {
44 const element = elements[eIdx];
45
46 if (element[BSONElementOffset.nameLength] === 2) {
47 const nameOffset = element[BSONElementOffset.nameOffset];
48
49 // 111 == "o", 107 == "k"
50 if (bson[nameOffset] === 111 && bson[nameOffset + 1] === 107) {
51 const valueOffset = element[BSONElementOffset.offset];
52 const valueLength = element[BSONElementOffset.length];
53
54 // If any byte in the length of the ok number (works for any type) is non zero,
55 // then it is considered "ok: 1"
56 for (let i = valueOffset; i < valueOffset + valueLength; i++) {
57 if (bson[i] !== 0x00) return false;
58 }
59
60 return true;
61 }
62 }
63 }
64
65 return true;
66}
67
68/** @internal */
69export type MongoDBResponseConstructor = {

Callers 1

makeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected