fix(proxyTest): improve error handling and update default test URL
Made-with: Cursor
This commit is contained in:
parent
9bca03bff7
commit
89405125e6
1 changed files with 19 additions and 2 deletions
|
|
@ -1,8 +1,25 @@
|
|||
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;
|
||||
|
||||
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) {
|
||||
if (value === undefined || value === null) return "";
|
||||
return String(value).trim();
|
||||
|
|
@ -59,7 +76,7 @@ export async function testProxyUrl({ proxyUrl, testUrl, timeoutMs } = {}) {
|
|||
const message =
|
||||
err?.name === "AbortError"
|
||||
? "Proxy test timed out"
|
||||
: err?.message || String(err);
|
||||
: getErrorMessage(err);
|
||||
return { ok: false, status: 500, error: message };
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue