0

I've written the following code which runs ok (got HTTP response of 200) using the request library.

var request = require('request');
var auth = Buffer.from(`${oD.des.User}:${oD.des.Password}`).toString('base64');
var options = {
    'method': 'GET',
    'url': oD.dest.URL + path,
    'headers': {
        'Authorization': 'Basic ' + auth,
        'Proxy-Authorization': `Bearer ${accesstoken}`
    }

};
return await request(options, function (error, response) {
    if (error) {
        throw new Error(error);
    }
    console.log(response.body);
});

Now I'm doing the same with exactly the same value with superagent and I get an error.

var auth = Buffer.from(`${oD.des.User}:${oD.des.Password}`).toString('base64');
  return superagent
  .get(oD.dest.URL + path)
  .set('Proxy-Authorization', `Bearer ${accesstoken}}`)
  .set('Authorization', 'Basic ' + auth)
  .end((err, res) => {
      console.log(err);
  });

Here I got an error, why???

0: Error: getaddrinfo ENOTFOUND fdev.wa.glb.corp.srd fdev.wa.glb.corp.srd:443
[[StableObjectId]]: 1
code: "ENOTFOUND"
errno: "ENOTFOUND"

I'm struggling with it for almost two days.

Beno Odr
  • 1,123
  • 1
  • 13
  • 27
  • How the `path` is defined in both examples? – Sebastian Kaczmarek Aug 03 '20 at 15:27
  • @SebastianKaczmarek - the path is exactly the same value (double/ triple check it )... myabe in superagent I should add another property ? – Beno Odr Aug 03 '20 at 15:32
  • `ENOTFOUND` means the DNS server you're using (or a DNS server in the chain) couldn't resolve the hostname (`fdev.wa.glb.corp.srd`). This is possible for a host of reasons - do you have any special DNS configuration? Is that DNS internally published only? Is there any DNS round-robin'ing occuring? – wally Aug 03 '20 at 16:04
  • @wally - this is interesting, as the `reques`t library is able to make the request with `http200` response (success with the code as-is), do you think that the useragent uses the dns resolve differently ? – Beno Odr Aug 03 '20 at 16:14
  • @wally - the strange thing that when I run it with `request` it always provide ok response and very stable – Beno Odr Aug 03 '20 at 16:16
  • I don’t know anything about the library - it’s possible (but I’d expect it to use the same underlying getaddrinfo call via the OS in both code samples). Very curious that it’s fully reliable vs fully unreliable... I’ll be interested to know the solution myself! – wally Aug 03 '20 at 16:18

1 Answers1

0

superagent.get uses

oDes.dest.URL

and the other one is using

oD.dest.URL

It seems you have mixed some variable names there...

Torge Rosendahl
  • 482
  • 6
  • 17