Andrelec1
Andrelec1

Reputation: 382

nodejs request ECONNREFUSED

i have some ECONNREFUSED with 'request' module, but some time my request passe without error O_o ... So i make my request recurcive but this not solve the problème ...

let request     = require("request");
let currency = 'btceur';
let data = [];
let url             = "https://api.cryptowat.ch/markets/kraken/" + currency + "/price";
let nbTry           = 0;
let nbMaxTry        = 5;
let callbackRequest = (error, response, body) => {
    if (error || response.statusCode != 200) {
        console.log('error', 'error, retry ' + (nbTry + 1) + "/" + nbMaxTry);
        console.log(error);
        if (nbTry <= nbMaxTry) {
            nbTry++;
            request(url, callbackRequest);
        } else {
            console.log(data);
        }
    } else {
        let bodyjson             = JSON.parse(body);
        bodyjson.result.currency = currency;
        data.push(bodyjson.result);
        console.log(data);
    }
};
request(url, callbackRequest);

console output:

error error, retry 1/5
{ Error: connect ECONNREFUSED 69.164.196.116:443
    at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '69.164.196.116',
  port: 443 }
[ { price: 1113.5, currency: 'btceur' } ]

Upvotes: 1

Views: 3652

Answers (1)

robertklep
robertklep

Reputation: 203419

api.cryptowat.ch resolves to two IP-numbers, 23.239.28.55 and 69.164.196.116. The latter is giving issues (for me as well).

You could try using the former for each request as a temporary workaround:

let url = "https://23.239.28.55/markets/kraken/" + currency + "/price";

It doesn't seem to need a Host header, although it would probably be better if you passed one anyway:

request({ url, headers : { Host : 'api.cryptowat.ch' } }, callbackRequest);

Upvotes: 2

Related Questions