Not caught Error: Client network socket disconnected before secure TLS connection was established #277

@AidanWelch

Description

It's normal that some proxied requests fail, so I have simple error handling, the issue is that the error is not being caught and instead crashing the script,

import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch from 'node-fetch';
const agent = new HttpsProxyAgent( process.env.PROXY_STRING );
let err;
const casePageResponse = await fetch( `foo.bar`, { agent })
	.catch( e =>




    
 err = e );

Crashes with this error:

node:events:497
      throw er; // Unhandled 'error' event
Error: Client network socket disconnected before secure TLS connection was established
    at TLSSocket.onConnectEnd (node:_tls_wrap:1727:19)
    at TLSSocket.emit (node:events:531:35)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on TLSSocket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ECONNRESET',
  path: undefined,
  host: 'us-pr.oxylabs.io',
  port: 10000,
  localAddress: undefined

It doesn't get caught in the catch statement.