Error: getaddrinfo ENOTFOUND Node JS using protractor - node.js

I'm using this method to request a tokenDn
this.retornaTokenDnQA = function (Request, tokenAuth) {
return new Promise((resolve, reject) => {
Request.get({
"headers": { "content-type": "application/json", "Authorization": "Bearer " + tokenAuth },
"url": "https://urlqa-api.apps.pd01e.edc1.cf.company.com/transformation/api/jwt/generate",
"body": JSON.stringify({
"dn": "5094",
"claims": {
"country": "BRA",
"division": 1,
"user": "ULSCA301",
"roles": [
"agenda - Distribuidor",
"teste - teste"
],
"locale": {
"language": "pt",
"region": "BR"
}
}
})
}, (error, response, body) => {
if (error) {
return console.dir(error);
}
//console.log("inside: " + response.body);
resolve(response.body);
});
});
};//end function - retornaTokenDn
but this return the following erro message.
Error: getaddrinfo ENOTFOUND urlqa-api.apps.pd01e.edc1.cf.company.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:64:26) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'urlqa-api.apps.pd01e.edc1.cf.company.com'
}
**
The real problema is, this error only occur when I'm using a VPN connection to connect the network company. Using my home network this work normally.**
Or when I'm using vpn and send a request by postman using the same options the response is 200 , ok.
I'm using this method in a protractor automated test, I apreciate any help u can do. Thanks!!!

if the ENOTFOUND error is dependent on your network, I'd check if there is a proxy server in one of the networks.

Related

Axios - Getting socket hang up error while running it on docker container

I am trying to get results from third party API by using Axios npm. Using nested request, first request is to get the token and another one is to get results.
Below code is working fine in my local machine but not in Docker container.
var config = {
method: 'post',
url: gsecConfig.tokenUrl,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: data
};
axios(config)
.then(function (response) {
if (response.data.access_token) {
const config = {
headers: { Accept: 'application/json', Authorization: `Bearer ${response.data.access_token}` }
};
axios.get(gsecConfig.gsecUrl + gsecid, config)
.then(function (response) {
let supplierData = response.data;
res.status(200).json({
"data": supplierData
});
}).catch(function (error) {
res.json({
"errors": error.message,
"name": error.name
});
});
}
})
.catch(function (tokenError) {
if (tokenError) {
res.json({
"errors": tokenError.message,
"name": tokenError.name
});
}
});
});
Getting error like below
"message": "socket hang up",
"name": "Error",
"stack": "Error: socket hang up\n at createHangUpError (_http_client.js:323:15)\n at Socket.socketOnEnd (_http_client.js:426:23)\n at Socket.emit (events.js:203:15)\n at endReadableNT (_stream_readable.js:1129:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)",
"code": "ECONNRESET"
Thanks in advance!
If your server is not Kubernetes, you can change the publish mode to host (default is ingress), the problem will be solved. check this
You can change it in docker-stack like below:
ports:
- target: 3001
published: 3001
protocol: tcp
mode: host
But if this is Kubernetes with node clusters, you should use the ingress mode, I'm facing this issue and still stuck here. Hope someone can help.

One signal create notification REST API fails sometimes

I am using oneSignal for push notifications node.js. I am using the create notification api to send notification to the users, but i dont know why it works some times and sometimes gives timeout error
sendNotificationToUser(data) {
try {
var notificationData = {}
notificationData.app_id = oneSignalAppId
notificationData.headings = {
en: "Heading"
}
notificationData.contents = {
en: data.message
}
notificationData.include_player_ids = [data.deviceId]
var headers = {
"Content-Type": "application/json; charset=utf-8"
}
var options = {
host: "onesignal.com",
port: 443,
path: "/api/v1/notifications",
method: "POST",
headers: headers
}
var https = require("https")
var req = https.request(options, function (res) {
res.on("data", function (data1) {
console.log("Response:")
console.log(JSON.parse(data1))
})
})
req.on("error", function (e) {
console.log("ERROR:")
console.log(e)
})
req.write(JSON.stringify(notificationData))
req.end()
} catch (err) {
console.log("err in notification", err)
}
}
this api works 50% of times and 50% of times it responds with time out error, even all the inputs are correct
ERROR:
{
Error: connect ETIMEDOUT 104.18.225.52:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
address: '104.18.225.52',
port: 443
}
one simple solution is to directly hit the working ip, you can do this by including
host: 'onesignal.con' in headers and
host: '104.18.226.52' in options
this resolved my issue
to know more about how you can specify ip with host in https request
go here HTTPS request, specifying hostname and specific IP address

Can't make a POST request on Azure - EACCES

I have a Node application hosted in Azure as a Web App Bot. When I try to make a POST request with axios from that application, it gives me the following error:
{ Error: connect EACCES 172.30..etc etc
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
errno: 'EACCES',
code: 'EACCES',
syscall: 'connect',
address: '172.30..etc,etc',
port: 443,
config:
...
Locally, testing with Bot Framework Emulator it works like a charm.
Request:
let reqConfig = {
headers: {
"Authorization": '123etc etc',
"Content-Type": "application/json"
}
}
axios.post("https://_______", body, reqConfig).then(r => {
console.log(r);
}).catch(e => {
console.log('ERR: ', e);
})

nodeJS request POST To localhost:3000 ECONNREFUSED

At one point I just want to make a POST request to my rails server running on localhost:3000
If a use like postman on even cUrl I can ping my API
But kow, with my node app I want to do this :
var req_body = {
'my_id': id,
'dataTable': data }
var options = {
method: 'POST',
url: config.get('api_url') + 'end_tracking',
json: true,
body: req_body
}
// config.get('api_url') return http://localhost:3000/
request(options, function (error, response, body) {
console.log(error)
... }
this is what I get :
{ Error: connect ECONNREFUSED 127.0.0.1:3000
at Object.exports._errnoException (util.js:896:11)
at exports._exceptionWithHostPort (util.js:919:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1073:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3000 }
and as I said, if I do this request directly with postman, everything works !
I finally did it !
For a unknown reason, accessing localhost:3000, launched with rails s didn't work at all on my node server
but I worked when I started the rails server with rails s -b 0.0.0.0 !
how i did this , just use the same structure and i hope it works for you
request({
url: url, //URL to hit
method: 'post',
headers: headers,
timeout: 10000,
body: JSON.stringify(body)
}, function (error, result, body) {
if (error) {
console.log(error);
} else if (result.statusCode == 500) {
console.log('not found');
} else {
console.log('success')
}
});
hope it works.

'Error: connect ECONNREFUSED' When calling http.request

I am trying to run the following node code,
function getQuestions() {
var options = {
host: 'mysite.com',
path: '/services/v2/question.json',
headers: {
"Content-Type": "application/json",
"accept": "application/json; charset=UTF-8",
'Authorization': auth
}
};
http.request(options, function(response) {
console.log("Everything worked!");
}).on('error', function(e) {
console.log('problem with request: ' + e.stack);
});
}
But it always errors saying...
problem with request: Error: connect ECONNREFUSED
at errnoException (net.js:905:11)
at Object.afterConnect [as oncomplete] (net.js:896:19)
When I put the same info into Postman it works fine. Is there a way to debug this?
Update
Tried this...
var options = {
host: "google.com"
};
Same result so something must be wrong in my code. Any ideas?
It did end up being a proxy issue this...
var options = {
host: "proxy",
port: 80,
path: 'http://google.com'
};
Notice the proxy in host. I will mark as duplicate of this post

Resources