test(web-fetch-http): pin proxy failure text and document reason bounds
Co-authored-by: Elevator14B <[email protected]>
This commit is contained in:
1 parent
38921fcac5
commit
2e65fefdd9
4 files changed
+16
-6
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -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` 工具会在自己的错误包装层内把失败文本呈现给模型。
|
||||
|
||||
-----
|
||||
|
||||
|
||||
@@ -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<void>> {
|
||||
const env = { get: (name: string) => (name === 'HTTP_PROXY' || name === 'HTTPS_PROXY' ? { value: proxyUrl } : undefined) }
|
||||
async function installProxy(url = proxyUrl): Promise<() => Promise<void>> {
|
||||
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' }))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user