Skip to content

Commit

Permalink
Handle exceptions from agent addRequest() (#330)
Browse files Browse the repository at this point in the history
`tls.createSecureContext()` can throw exceptions, so `.addRequest()`
can throw exceptions as well.
  • Loading branch information
addaleax authored Dec 6, 2024
1 parent 96b771b commit 1699a09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-terms-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'agent-base': patch
---

Handle exceptions caused by Agent.addRequest()
8 changes: 6 additions & 2 deletions packages/agent-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ export abstract class Agent extends http.Agent {
(socket) => {
this.decrementSockets(name, fakeSocket);
if (socket instanceof http.Agent) {
// @ts-expect-error `addRequest()` isn't defined in `@types/node`
return socket.addRequest(req, connectOpts);
try {
// @ts-expect-error `addRequest()` isn't defined in `@types/node`
return socket.addRequest(req, connectOpts);
} catch (err: unknown) {
return cb(err as Error);
}
}
this[INTERNAL].currentSocket = socket;
// @ts-expect-error `createSocket()` isn't defined in `@types/node`
Expand Down

0 comments on commit 1699a09

Please sign in to comment.