0
我有一些ECONNREFUSED與「請求」模塊,但有些時候我的請求過時沒有錯誤O_O ... 所以我讓我的請求recurcive但這不能解決problème...要求的NodeJS ECONNREFUSED
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);
控制檯輸出:
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' } ]
是的,恆定的IP解決了與Promise.all類似的問題。 –