From 2000c2ddf659a4221205452530f01c02d0108525 Mon Sep 17 00:00:00 2001 From: Gauthier Date: Thu, 31 Oct 2024 02:08:06 +0100 Subject: [PATCH] fix: add error handling for proxy creating --- server/utils/customProxyAgent.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/server/utils/customProxyAgent.ts b/server/utils/customProxyAgent.ts index 6efde1943..3b6223685 100644 --- a/server/utils/customProxyAgent.ts +++ b/server/utils/customProxyAgent.ts @@ -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' });