(url: string)
| 85 | } |
| 86 | |
| 87 | export function getProxyAgent(url: string): HttpProxyAgent<string> | HttpsProxyAgent<string> | undefined { |
| 88 | try { |
| 89 | const uri = new URL(url) |
| 90 | const proxy = getProxyFromURI(uri) |
| 91 | |
| 92 | if (!proxy) { |
| 93 | return undefined |
| 94 | } else if (uri.protocol === 'http:') { |
| 95 | try { |
| 96 | return new HttpProxyAgent(proxy) |
| 97 | } catch (agentError) { |
| 98 | throw new Error( |
| 99 | `Error while instantiating HttpProxyAgent with URL: "${proxy}"\n${agentError}\nCheck the following env vars "http_proxy" or "HTTP_PROXY". The value should be a valid URL starting with "http://"`, |
| 100 | ) |
| 101 | } |
| 102 | } else if (uri.protocol === 'https:') { |
| 103 | try { |
| 104 | return new HttpsProxyAgent(proxy) |
| 105 | } catch (agentError) { |
| 106 | throw new Error( |
| 107 | `Error while instantiating HttpsProxyAgent with URL: "${proxy}"\n${agentError}\nCheck the following env vars "https_proxy" or "HTTPS_PROXY". The value should be a valid URL starting with "https://"`, |
| 108 | ) |
| 109 | } |
| 110 | } |
| 111 | } catch (e) { |
| 112 | console.warn(`An error occurred in getProxyAgent(), no proxy agent will be used.`, e) |
| 113 | } |
| 114 | |
| 115 | return undefined |
| 116 | } |
no test coverage detected