Not caught Error: Client network socket disconnected before secure TLS connection was established
AidanWelch opened this issue · 4 comments
AidanWelch commented
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.
AidanWelch commented
Probably an error with node-fetch as seen on this tangentially related issue: node-fetch/node-fetch#892
AidanWelch commented
Actually I get it with node:https too, also not being caught by req.on('error', console.error)
AidanWelch commented
passing rejectUnauthorized
like so:
const agent = new HttpsProxyAgent( process.env.PROXY_STRING, { rejectUnauthorized: false });
stops this error specifically, but the issue is still that it doesn't throw the error.
florrdv commented
Having the same issue here!