diff --git a/packages/web/web-fetch-http/README.i18n.yaml b/packages/web/web-fetch-http/README.i18n.yaml index cd38c41c24..9010001d0c 100644 --- a/packages/web/web-fetch-http/README.i18n.yaml +++ b/packages/web/web-fetch-http/README.i18n.yaml @@ -30,8 +30,8 @@ en: 4c5618124337446e zh: 45c7378c8b0bba45 /deepseek-ai-dsh-web-fetch-http/use-this-package/failures-and-recovery: - en: 7767aae6d0d5d969 - zh: ba93fa27403d4e6f + en: e62633ede6519943 + zh: 0970dc75b474e702 /deepseek-ai-dsh-web-fetch-http/understand-the-implementation: en: 9842c69ad3636bb3 zh: 3cdc3f816cbdd0cb diff --git a/packages/web/web-fetch-http/README.md b/packages/web/web-fetch-http/README.md index 7e0ab8897c..d8233c9429 100644 --- a/packages/web/web-fetch-http/README.md +++ b/packages/web/web-fetch-http/README.md @@ -67,7 +67,7 @@ A malformed comma- or whitespace-joined charset declaration containing a UTF-8 l ### Failures and recovery -Failures throw `WebError` with a machine-routable code: `WEB_INVALID_URL`, `WEB_BLOCKED_URL`, `WEB_FETCH_TOO_LARGE`, `WEB_FETCH_TIMEOUT`, `WEB_REDIRECT_BLOCKED`, `WEB_UNSUPPORTED_CONTENT_TYPE`, `WEB_ABORTED`, or `WEB_PROVIDER_ERROR`. `WEB_UNSUPPORTED_CONTENT_TYPE` covers unsupported media types, unsupported charset declarations, and invalid UTF-8 during malformed-declaration recovery. A `WEB_PROVIDER_ERROR` from a transport failure names the underlying system error, such as `getaddrinfo ENOTFOUND host`, `connect ECONNREFUSED addr:port`, or a TLS certificate error. Direct callers can route on the code; the model-facing `web_fetch` tool surfaces the failure text to the model under its own error wrapper. +Failures throw `WebError` with a machine-routable code: `WEB_INVALID_URL`, `WEB_BLOCKED_URL`, `WEB_FETCH_TOO_LARGE`, `WEB_FETCH_TIMEOUT`, `WEB_REDIRECT_BLOCKED`, `WEB_UNSUPPORTED_CONTENT_TYPE`, `WEB_ABORTED`, or `WEB_PROVIDER_ERROR`. `WEB_UNSUPPORTED_CONTENT_TYPE` covers unsupported media types, unsupported charset declarations, and invalid UTF-8 during malformed-declaration recovery. A `WEB_PROVIDER_ERROR` from a transport failure names the underlying system error, such as `getaddrinfo ENOTFOUND host`, `connect ECONNREFUSED addr:port`, or a TLS certificate error; it lists at most four connection attempts, counts the rest, and keeps at most 500 characters of the reason. Direct callers can route on the code; the model-facing `web_fetch` tool surfaces the failure text to the model under its own error wrapper. ----- diff --git a/packages/web/web-fetch-http/README.zh.md b/packages/web/web-fetch-http/README.zh.md index 40f97cd6f2..ca1be3eb39 100644 --- a/packages/web/web-fetch-http/README.zh.md +++ b/packages/web/web-fetch-http/README.zh.md @@ -67,7 +67,7 @@ const page = await ctx.web.fetch({ url: 'https://example.com' }) ### 失败与恢复 -失败会抛出 `WebError`,其中包含可供程序路由的错误码:`WEB_INVALID_URL`、`WEB_BLOCKED_URL`、`WEB_FETCH_TOO_LARGE`、`WEB_FETCH_TIMEOUT`、`WEB_REDIRECT_BLOCKED`、`WEB_UNSUPPORTED_CONTENT_TYPE`、`WEB_ABORTED` 或 `WEB_PROVIDER_ERROR`。`WEB_UNSUPPORTED_CONTENT_TYPE` 涵盖不支持的媒体类型、不支持的 charset 声明,以及畸形声明恢复过程中遇到的非法 UTF-8。传输失败产生的 `WEB_PROVIDER_ERROR` 会给出底层系统错误,例如 `getaddrinfo ENOTFOUND host`、`connect ECONNREFUSED addr:port` 或 TLS 证书错误。直接调用方可以按错误码路由;面向模型的 `web_fetch` 工具会在自己的错误包装层内把失败文本呈现给模型。 +失败会抛出 `WebError`,其中包含可供程序路由的错误码:`WEB_INVALID_URL`、`WEB_BLOCKED_URL`、`WEB_FETCH_TOO_LARGE`、`WEB_FETCH_TIMEOUT`、`WEB_REDIRECT_BLOCKED`、`WEB_UNSUPPORTED_CONTENT_TYPE`、`WEB_ABORTED` 或 `WEB_PROVIDER_ERROR`。`WEB_UNSUPPORTED_CONTENT_TYPE` 涵盖不支持的媒体类型、不支持的 charset 声明,以及畸形声明恢复过程中遇到的非法 UTF-8。传输失败产生的 `WEB_PROVIDER_ERROR` 会给出底层系统错误,例如 `getaddrinfo ENOTFOUND host`、`connect ECONNREFUSED addr:port` 或 TLS 证书错误;最多列出四次连接尝试,其余只计数,原因文本最多保留 500 个字符。直接调用方可以按错误码路由;面向模型的 `web_fetch` 工具会在自己的错误包装层内把失败文本呈现给模型。 ----- diff --git a/packages/web/web-fetch-http/tests/proxy.spec.ts b/packages/web/web-fetch-http/tests/proxy.spec.ts index 88c11883ff..3d30630828 100644 --- a/packages/web/web-fetch-http/tests/proxy.spec.ts +++ b/packages/web/web-fetch-http/tests/proxy.spec.ts @@ -63,8 +63,8 @@ afterEach(async () => { * Install the policy of a user who exported one proxy for both schemes; the fixture disposes it * after every case. */ -async function installProxy(): Promise<() => Promise> { - const env = { get: (name: string) => (name === 'HTTP_PROXY' || name === 'HTTPS_PROXY' ? { value: proxyUrl } : undefined) } +async function installProxy(url = proxyUrl): Promise<() => Promise> { + const env = { get: (name: string) => (name === 'HTTP_PROXY' || name === 'HTTPS_PROXY' ? { value: url } : undefined) } return await installProxyFromEnvironment(env, () => undefined) } @@ -108,4 +108,14 @@ describe('fetching through a proxy', () => { .rejects.toThrow(expect.objectContaining({ code: 'WEB_INVALID_URL' })) expect(proxied).toEqual([]) }) + + it('names a proxy transport failure without the proxy credentials', async () => { + proxy.removeAllListeners('request') + proxy.on('request', (request) => { request.socket.end() }) + disposeProxy = await installProxy(proxyUrl.replace('http://', 'http://proxy-user:proxy-secret@')) + + const failure = new HttpFetchProvider(limits).fetch({ url: proxyTarget }) + + await expect(failure).rejects.toThrow(expect.objectContaining({ code: 'WEB_PROVIDER_ERROR', message: 'web fetch failed: other side closed' })) + }) })