user1740962
user1740962

Reputation: 121

throw er; event.js http.get with proxy

    var tabProxy = new Array(
    '122.72.76.122'
    ,'124.240.187.79'
     );
 http.get ({
            host: tabProxy[selectorProxy],
            port: 80,
            path: baseurl + counter
        }, function (response) {
            try{
                var statusCode = response.statusCode;
                console.log (statusCode);
             }catch(e){
            console.log(e);
        }
    })

with selectorProxy =0; it work but with selectorProxy = 1; app crach :

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: socket hang up
    at createHangUpError (http.js:1417:15)
    at Socket.socketOnEnd [as onend] (http.js:1513:23)
    at Socket.g (events.js:175:14)
    at Socket.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:870:14
    at process._tickCallback (node.js:415:13)

how to recup this error ( for extract this ip of my array ) ? the try catch doesn't work !!

Upvotes: 0

Views: 5419

Answers (1)

Bret Copeland
Bret Copeland

Reputation: 24070

Your try/catch doesn't cover anything which would throw an error. More to the point, you need to listen for the 'error' event on your request.

var req = http.get(options, function (res) { ... });
req.on('error', function (err) {
    //handle error here
});

Upvotes: 4

Related Questions