fix: add error handling for proxy creating

This commit is contained in:
Gauthier
2024-10-31 02:08:06 +01:00
parent 4a3fb5e6c8
commit 2000c2ddf6

View File

@@ -52,17 +52,27 @@ export default async function createCustomProxyAgent(
).toString('base64')}`
: undefined;
const proxyAgent = new ProxyAgent({
uri: proxySettings.useSsl
? 'https://'
: 'http://' + proxySettings.hostname + ':' + proxySettings.port,
token,
interceptors: {
Client: [noProxyInterceptor],
},
});
try {
const proxyAgent = new ProxyAgent({
uri:
(proxySettings.useSsl ? 'https://' : 'http://') +
proxySettings.hostname +
':' +
proxySettings.port,
token,
interceptors: {
Client: [noProxyInterceptor],
},
});
setGlobalDispatcher(proxyAgent);
setGlobalDispatcher(proxyAgent);
} catch (e) {
logger.error('Failed to connect to the proxy: ' + e.message, {
label: 'Proxy',
});
setGlobalDispatcher(defaultAgent);
return;
}
try {
const res = await fetch('https://www.google.com', { method: 'HEAD' });