Skip to content

Commit

Permalink
fix: reject promise if deserializeMessage throws
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed May 16, 2024
1 parent eff419f commit e0b4b7d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/protocol/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ export class WireProtocol {
if (!bodyBuffer) {
throw new MongoDriverError("Invalid response body");
}
const reply = deserializeMessage(header, bodyBuffer);
const pendingMessage = this.#pendingResponses.get(header.responseTo);
this.#pendingResponses.delete(header.responseTo);
pendingMessage?.resolve(reply);
try {
const reply = deserializeMessage(header, bodyBuffer);
pendingMessage?.resolve(reply);
} catch (e) {
pendingMessage?.reject(e)
}
}
this.#isPendingResponse = false;
}
Expand Down

0 comments on commit e0b4b7d

Please sign in to comment.