refactor(cli): proxy failure wording without added comments or a try/catch

This commit is contained in:
Miguel Angel Simon Sierra
2026-10-29 00:36:08 -04:00
parent 11312b359b
commit df71defeda
@@ -9,8 +9,6 @@ export { isNavigationTimeoutError };
export const NETWORK_IDLE_ATTEMPT_MS = 30_000;
/** Chromium's words for a proxy in the way: the tunnel to the site was refused or not made, or the proxy itself
* could not be reached. */
const PROXY_FAILURES = {
"net::ERR_TUNNEL_CONNECTION_FAILED": (host: string) =>
`Your network's proxy refused the connection to ${host}. Ask whoever runs it to allow ${host}.`,
@@ -19,17 +17,11 @@ const PROXY_FAILURES = {
} as const;
const PROXY_FAILURE = new RegExp(Object.keys(PROXY_FAILURES).join("|"));
/** The error as the person should read it when their network's proxy was the problem; any other error as is. */
export function explainProxyRefusal(err: unknown, url: string): unknown {
const said = err instanceof Error ? err.message : String(err);
const code = PROXY_FAILURE.exec(said)?.[0] as keyof typeof PROXY_FAILURES | undefined;
if (!code) return err;
let host = "the site";
try {
host = new URL(url).host;
} catch {
// expected: an unparseable address is not echoed
}
const host = URL.canParse(url) ? new URL(url).host : "the site";
return new Error(`${PROXY_FAILURES[code](host)} (${code})`, { cause: err });
}