mirror of
https://github.com/GMGNAI/gmgn-skills.git
synced 2026-07-27 16:57:44 +00:00
use ipv4
This commit is contained in:
@@ -249,7 +249,17 @@ export class OpenApiClient {
|
||||
try {
|
||||
return await fetch(url, { method, headers, body: body ?? undefined });
|
||||
} catch (err: unknown) {
|
||||
const cause = err instanceof Error ? (err.cause ?? err) : err;
|
||||
const cause = extractRootCause(err);
|
||||
const errorCode = (cause as NodeJS.ErrnoException).code;
|
||||
|
||||
// Detect IPv4 unavailability errors
|
||||
if (errorCode === "EADDRNOTAVAIL" || errorCode === "ENETUNREACH") {
|
||||
throw new Error(
|
||||
`Network unreachable (${errorCode}): Your system may not support IPv4. ` +
|
||||
`Please check your network configuration or contact support.`
|
||||
);
|
||||
}
|
||||
|
||||
if (process.env.GMGN_DEBUG) console.error(`${curlStr}\n[error] fetch failed: ${cause}`);
|
||||
throw new Error(`${method} ${subPath} fetch failed: ${cause}`);
|
||||
}
|
||||
@@ -362,3 +372,11 @@ function buildUrl(base: string, query: Record<string, string | number | string[]
|
||||
}
|
||||
return `${base}?${params.toString()}`;
|
||||
}
|
||||
|
||||
// Recursively extract the root cause from nested Error.cause chain
|
||||
function extractRootCause(err: unknown): unknown {
|
||||
if (err instanceof Error && err.cause) {
|
||||
return extractRootCause(err.cause);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
+6
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
import { createRequire } from "module";
|
||||
const { version } = createRequire(import.meta.url)("../package.json") as { version: string };
|
||||
import { setGlobalDispatcher, ProxyAgent, Agent } from "undici";
|
||||
import { setGlobalDispatcher, ProxyAgent, Agent, buildConnector } from "undici";
|
||||
import { SocksClient } from "socks";
|
||||
import * as tls from "tls";
|
||||
import { Command } from "commander";
|
||||
@@ -25,6 +25,7 @@ if (proxy) {
|
||||
proxy: { host: u.hostname, port: parseInt(u.port || "1080"), type },
|
||||
command: "connect",
|
||||
destination: { host: options.hostname!, port: +options.port! },
|
||||
socket_options: { family: 4 } as any,
|
||||
});
|
||||
if (options.protocol === "https:") {
|
||||
callback(null, tls.connect({ socket, servername: options.hostname, rejectUnauthorized: options.rejectUnauthorized !== false }));
|
||||
@@ -39,6 +40,10 @@ if (proxy) {
|
||||
} else {
|
||||
setGlobalDispatcher(new ProxyAgent(proxy));
|
||||
}
|
||||
} else {
|
||||
// Force IPv4 for all connections (no proxy mode)
|
||||
const connector = buildConnector({ family: 4 } as any);
|
||||
setGlobalDispatcher(new Agent({ connect: connector }));
|
||||
}
|
||||
|
||||
const program = new Command();
|
||||
|
||||
Reference in New Issue
Block a user