Fix proxy handling in WAStartupService preventing instance to be created

This commit is contained in:
Judson Junior 2024-01-21 13:01:35 -03:00
parent 1e9b3a1e42
commit 82e111f1be

View File

@ -1384,14 +1384,18 @@ export class WAStartupService {
this.logger.info('Proxy enabled: ' + this.localProxy.proxy); this.logger.info('Proxy enabled: ' + this.localProxy.proxy);
if (this.localProxy.proxy.host.includes('proxyscrape')) { if (this.localProxy.proxy.host.includes('proxyscrape')) {
const response = await axios.get(this.localProxy.proxy.host); try {
const text = response.data; const response = await axios.get(this.localProxy.proxy.host);
const proxyUrls = text.split('\r\n'); const text = response.data;
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length)); const proxyUrls = text.split('\r\n');
const proxyUrl = 'http://' + proxyUrls[rand]; const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
options = { const proxyUrl = 'http://' + proxyUrls[rand];
agent: new ProxyAgent(proxyUrl as any), options = {
}; agent: new ProxyAgent(proxyUrl as any),
};
} catch (error) {
this.localProxy.enabled = false;
}
} else { } else {
let proxyUri = let proxyUri =
this.localProxy.proxy.protocol + '://' + this.localProxy.proxy.host + ':' + this.localProxy.proxy.port; this.localProxy.proxy.protocol + '://' + this.localProxy.proxy.host + ':' + this.localProxy.proxy.port;