My application crashes after a while with this error:
{ Error: connect ETIMEDOUT 31.13.92.51:443 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: '31.13.92.51', 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('https://www.instagram.com/'+username+'/?__a=1', function(resp){
var body = '';
resp.setEncoding('utf8');
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);
return;
}
callback(null, json.user);
});
});
}catch (error){
callback("Connection to Instagram failed.", null);
}