In fetch.js file I think there is a mistype:
op.once('errror', reject); should be op.once('error', reject); (There is an extra 'r' in 'error'). But thats not the main issue I want to address here.
After performing few thousand of request occasionally I get:
Error: connect ETIMEDOUT 92.122.156.90:443 at Object._errnoException (util.js:992:11) at _exceptionWithHostPort (util.js:1014:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
I have fixed this by catching the error after fetch in fetch.js
return new Promise((resolve, reject) => {
fetch(options, res => {
const ce = res.headers['content-encoding'];
let data = '';
let op = res;
if (ce === 'deflate') res.pipe(op = createDeflate());
if (ce === 'gzip') res.pipe(op = createGunzip());
op.on('data', chunk => data += chunk);
op.on('error', reject);
op.once('end', () => {
if (res.statusCode === 500) return reject(new Error('Internal server error'));
if (res.statusCode === 403) return reject(new Error('Invalid key'));
if (res.statusCode === 400) return reject(new Error(reg.test(data) ? data.match(reg)[1] : data));
if (res.statusCode !== 200) return reject(new Error(res.statusMessage));
try {
resolve(JSON.parse(data));
} catch (_) {
reject(new Error(data));
}
});
}).on("error", function(error){
console.log(error);
});
});
In fetch.js file I think there is a mistype:
op.once('errror', reject);
should beop.once('error', reject);
(There is an extra 'r' in 'error'). But thats not the main issue I want to address here.After performing few thousand of request occasionally I get:
Error: connect ETIMEDOUT 92.122.156.90:443 at Object._errnoException (util.js:992:11) at _exceptionWithHostPort (util.js:1014:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
I have fixed this by catching the error after fetch in fetch.js