fix(update): cancel npm registry error bodies · openclaw/openclaw@86a2863
vincentkoc
·
2026-06-19
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -219,6 +219,24 @@ describe("resolveNpmChannelTag", () => {
|
219 | 219 | ); |
220 | 220 | }); |
221 | 221 | |
| 222 | +it("cancels public registry HTTP failure bodies", async () => { |
| 223 | +const cancel = vi.fn(async () => undefined); |
| 224 | +const fetch = vi.fn( |
| 225 | +async () => ({ ok: false, status: 503, body: { cancel } }) as unknown as Response, |
| 226 | +); |
| 227 | +vi.stubGlobal("fetch", fetch); |
| 228 | + |
| 229 | +await expect( |
| 230 | +fetchNpmPackageTargetStatus({ target: "latest", timeoutMs: 1000 }), |
| 231 | +).resolves.toEqual({ |
| 232 | +target: "latest", |
| 233 | +version: null, |
| 234 | +nodeEngine: null, |
| 235 | +error: "HTTP 503", |
| 236 | +}); |
| 237 | +expect(cancel).toHaveBeenCalledTimes(1); |
| 238 | +}); |
| 239 | + |
222 | 240 | it("falls back to latest when beta is older", async () => { |
223 | 241 | versionByTag.beta = "1.0.0-beta.1"; |
224 | 242 | versionByTag.latest = "1.0.1-1"; |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -110,8 +110,9 @@ async function fetchPublicNpmPackageTargetStatus(params: {
|
110 | 110 | target: string; |
111 | 111 | timeoutMs: number; |
112 | 112 | }): Promise<NpmPackageTargetStatus> { |
| 113 | +let res: Response | undefined; |
113 | 114 | try { |
114 | | -const res = await fetchWithTimeout( |
| 115 | +res = await fetchWithTimeout( |
115 | 116 | `https://registry.npmjs.org/openclaw/${encodeURIComponent(params.target)}`, |
116 | 117 | {}, |
117 | 118 | Math.max(250, params.timeoutMs), |
@@ -135,6 +136,10 @@ async function fetchPublicNpmPackageTargetStatus(params: {
|
135 | 136 | }; |
136 | 137 | } catch (err) { |
137 | 138 | return { target: params.target, version: null, nodeEngine: null, error: String(err) }; |
| 139 | +} finally { |
| 140 | +if (res?.bodyUsed !== true) { |
| 141 | +await res?.body?.cancel().catch(() => undefined); |
| 142 | +} |
138 | 143 | } |
139 | 144 | } |
140 | 145 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。