Skip to content

Commit 8d413aa

Browse files
authored
fix: 提示用户关闭代理以解决网络报错 (#49)
当上传文件时遇到代理/VPN相关的网络错误(如 TLS 握手失败、 ECONNRESET 等),在错误信息中追加提示,引导用户关闭代理后重试。 覆盖的错误类型: - TLS 连接建立前 socket 断开 - ECONNRESET / ECONNREFUSED / ETIMEDOUT - 自签名证书相关错误 - EHOSTUNREACH / ENETUNREACH
1 parent 78cc077 commit 8d413aa

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/api.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,45 @@ function createRequestError(
9595
return requestError;
9696
}
9797

98+
const PROXY_ERROR_PATTERNS = [
99+
'socket disconnected before secure TLS connection',
100+
'ECONNRESET',
101+
'ECONNREFUSED',
102+
'DEPTH_ZERO_SELF_SIGNED_CERT',
103+
'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
104+
'CERT_HAS_EXPIRED',
105+
'self signed certificate',
106+
'proxy',
107+
'ETIMEDOUT',
108+
'EHOSTUNREACH',
109+
'ENETUNREACH',
110+
];
111+
112+
function isProxyRelatedError(error: unknown): boolean {
113+
const msg =
114+
error instanceof Error
115+
? error.message
116+
: typeof error === 'string'
117+
? error
118+
: '';
119+
const lower = msg.toLowerCase();
120+
return PROXY_ERROR_PATTERNS.some((p) => lower.includes(p.toLowerCase()));
121+
}
122+
98123
async function query(url: string, options: RuntimeRequestInit) {
99124
const baseUrl = await getBaseUrl;
100125
const fullUrl = `${baseUrl}${url}`;
101126
let resp: RuntimeResponse;
102127
try {
103128
resp = await runtimeFetch(fullUrl, options);
104129
} catch (error) {
105-
throw createRequestError(error, fullUrl);
130+
const baseError = createRequestError(error, fullUrl);
131+
if (isProxyRelatedError(error)) {
132+
throw new Error(
133+
`${baseError.message}\n\n${t('proxyNetworkError')}\n${t('proxyNetworkErrorTips')}`,
134+
);
135+
}
136+
throw baseError;
106137
}
107138
const text = await resp.text();
108139
let json: any;
@@ -230,6 +261,13 @@ export async function uploadFile(fn: string, key?: string) {
230261
body: form,
231262
});
232263
} catch (error) {
264+
if (isProxyRelatedError(error)) {
265+
const rawMessage =
266+
error instanceof Error ? error.message : String(error);
267+
throw new Error(
268+
`${rawMessage}\n\n${t('proxyNetworkError')}\n${t('proxyNetworkErrorTips')}`,
269+
);
270+
}
233271
throw createRequestError(error, realUrl);
234272
}
235273

src/locales/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,7 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
182182
nodeHdiffpatchRequired:
183183
'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
184184
apkExtracted: 'APK extracted to {{output}}',
185+
proxyNetworkError:
186+
'Network error — likely caused by a proxy/VPN. Please try disabling your proxy and retry.',
187+
proxyNetworkErrorTips: 'Common fixes:\n1. Disable system proxy or VPN\n2. Check HTTP_PROXY / HTTPS_PROXY environment variables\n3. Check proxy settings in .npmrc',
185188
};

src/locales/zh.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,7 @@ export default {
168168
nodeHdiffpatchRequired:
169169
'此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
170170
apkExtracted: 'APK 已提取到 {{output}}',
171+
proxyNetworkError:
172+
'网络连接异常,可能是代理/VPN 导致。请尝试关闭代理后重试。',
173+
proxyNetworkErrorTips: '常见解决方法:\n1. 关闭系统代理或 VPN\n2. 检查 HTTP_PROXY / HTTPS_PROXY 环境变量\n3. 检查 .npmrc 中的 proxy 配置',
171174
};

0 commit comments

Comments
 (0)