Skip to content

Commit

Permalink
fix: reject promise if deserializeMessage throws (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning authored May 19, 2024
1 parent d917442 commit 1ade65f
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 @@ -120,10 +120,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 1ade65f

Please sign in to comment.