node-tunnel icon indicating copy to clipboard operation
node-tunnel copied to clipboard

bad proxy will raise exception: TypeError: options.request.emit is not a function

Open sshxmz opened this issue 5 years ago • 4 comments

When I use an agent created by tunnel with proxy, if the proxy is not reachable, wrong exception raised.

Simple codes:

let a = tunnel.httpOverHttp({proxy: {host: 'nosuch.host.com', port: 8080}});
    return got(anurl, {agent: a})
    .then( res => {
        if (res.statusCode === 200) return res.body;
        else throw new Error('http status ' + res.statusCode + ', ' + res.body);
    }); 

exception raised:

TypeError: options.request.emit is not a function
    at ClientRequest.onError (/home/xxx/nodejs/proxylib/node_modules/tunnel/lib/tunnel.js:183:21)
    at Object.onceWrapper (events.js:300:26)
    at ClientRequest.emit (events.js:210:5)
    at Socket.socketErrorListener (_http_client.js:406:9)
    at Socket.emit (events.js:210:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

But EHOSTNOTFOUND or ENETWORK are expected error.

sshxmz avatar Dec 07 '19 15:12 sshxmz

I am getting this as well

KhafraDev avatar Dec 08 '19 00:12 KhafraDev

I had the same issue, it appeared that I have used the wrong config

malsatin avatar Jan 05 '20 00:01 malsatin

Same issue here

abriginets avatar Jan 16 '20 00:01 abriginets

if authentication parameters are bad or any proxy parameter is bad, exceptions are thrown.. Is there a way to catch these exceptions and show to the user what went wrong?

nikhell86 avatar Jul 27 '21 10:07 nikhell86