mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
fix(proxyTest): improve error handling and update default test URL
Made-with: Cursor
This commit is contained in:
@@ -1,8 +1,25 @@
|
|||||||
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
||||||
|
|
||||||
const DEFAULT_TEST_URL = "https://example.com/";
|
const DEFAULT_TEST_URL = "https://google.com/";
|
||||||
const DEFAULT_TIMEOUT_MS = 8000;
|
const DEFAULT_TIMEOUT_MS = 8000;
|
||||||
|
|
||||||
|
function getErrorMessage(err) {
|
||||||
|
if (!err) return "Unknown error";
|
||||||
|
const base = err?.message || String(err);
|
||||||
|
const causeCode = err?.cause?.code || err?.code;
|
||||||
|
const causeMessage = err?.cause?.message;
|
||||||
|
|
||||||
|
if (causeMessage && causeMessage !== base) {
|
||||||
|
return causeCode ? `${base}: ${causeMessage} (${causeCode})` : `${base}: ${causeMessage}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (causeCode && !base.includes(causeCode)) {
|
||||||
|
return `${base} (${causeCode})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeString(value) {
|
function normalizeString(value) {
|
||||||
if (value === undefined || value === null) return "";
|
if (value === undefined || value === null) return "";
|
||||||
return String(value).trim();
|
return String(value).trim();
|
||||||
@@ -59,7 +76,7 @@ export async function testProxyUrl({ proxyUrl, testUrl, timeoutMs } = {}) {
|
|||||||
const message =
|
const message =
|
||||||
err?.name === "AbortError"
|
err?.name === "AbortError"
|
||||||
? "Proxy test timed out"
|
? "Proxy test timed out"
|
||||||
: err?.message || String(err);
|
: getErrorMessage(err);
|
||||||
return { ok: false, status: 500, error: message };
|
return { ok: false, status: 500, error: message };
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
|||||||
Reference in New Issue
Block a user