Skip to content

Commit 00ed0a1

Browse files
luisAzcuagaclaude
andcommitted
fix: add safe destroy check for proxy agents in terminate method
Proxy agents like tunnel-agent and hpagent may not implement the standard destroy() method, causing TypeError when the interceptor attempts cleanup. Added proper type checking before calling agent.destroy() to prevent crashes with CONNECT tunneling requests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 158eb2c commit 00ed0a1

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/interceptors/ClientRequest/NodeClientRequest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ export class NodeClientRequest extends ClientRequest {
609609
* debatable, but we should still handle this case gracefully.
610610
* @see https://github.com/mswjs/interceptors/issues/304
611611
*/
612-
// @ts-ignore
613-
this.agent?.destroy()
612+
const agent = (this as any).agent
613+
if (agent && typeof agent.destroy === 'function') {
614+
agent.destroy()
615+
}
614616
}
615617
}

0 commit comments

Comments
 (0)