user234 user234 - 2 months ago 59
Node.js Question

Error: socket hang up using https

My application crashes after a while with this error:

{ Error: connect ETIMEDOUT
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14) code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect',

address: '', port: 443 }

{ Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at TLSSocket.socketCloseListener (_http_client.js:285:23)
at emitOne (events.js:101:20)
at TLSSocket.emit (events.js:188:7)
at _handle.close (net.js:497:12)
at TCP.done [as _onclose] (_tls_wrap.js:332:7) code: 'ECONNRESET' }

I don't see anything wrong in my code, how can i handle this error?

try {
https.get(''+username+'/?__a=1', function(resp){
var body = '';
resp.on('data', function (chunk) {
body += chunk;
resp.on('end', function () {
try {
var json = JSON.parse(body);
} catch (error) {
callback('Unable to fetch user info from Instagram.', null);
callback(null, json.user);
}catch (error){
callback("Connection to Instagram failed.", null);

Answer Source

I have tried the same with https module, I've had the same problem, so I decided to go with another module which is request module, it seemed to work fine. I don't know why but https can't get resp from , as I've tried already. This is what you can try as it worked for me. Install request module

    var request = require("request");
    var ext = '/?__a=1';
    var username = //username here;

      .get(''+ username + ext)
      .on('response', function(response) {
        console.log(response.statusCode) // 200 is what I get from request