fix(proxy): Add error handling to proxy agent creation (#11538)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Shreya Keshive
2025-10-21 12:43:37 -07:00
committed by GitHub
parent 62dc9683bd
commit e72c00cf9a
3 changed files with 17 additions and 6 deletions
+9
View File
@@ -6,6 +6,7 @@
import { getErrorMessage, isNodeError } from './errors.js';
import { URL } from 'node:url';
import { ProxyAgent, setGlobalDispatcher } from 'undici';
const PRIVATE_IP_RANGES = [
/^10\./,
@@ -55,3 +56,11 @@ export async function fetchWithTimeout(
clearTimeout(timeoutId);
}
}
export function setGlobalProxy(proxy: string) {
try {
setGlobalDispatcher(new ProxyAgent(proxy));
} catch (e) {
console.error(`Failed to set proxy: ${getErrorMessage(e)}`);
}
}