Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exceptions from agent addRequest() #330

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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