From aab7a21dca98758a07827175ec993060ec62ee0a Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 12 Apr 2024 15:07:38 -0700 Subject: [PATCH] fetch: Change wording of "Body is unusable" error fixes #3097 --- lib/web/fetch/body.js | 2 +- test/fetch/client-fetch.js | 4 ++-- test/node-fetch/main.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/web/fetch/body.js b/lib/web/fetch/body.js index 26cce5f3e0c..2f560b237e5 100644 --- a/lib/web/fetch/body.js +++ b/lib/web/fetch/body.js @@ -406,7 +406,7 @@ async function consumeBody (object, convertBytesToJSValue, instance) { // 1. If object is unusable, then return a promise rejected // with a TypeError. if (bodyUnusable(object[kState].body)) { - throw new TypeError('Body is unusable') + throw new TypeError('Body is unusable: Body has already been read') } throwIfAborted(object[kState]) diff --git a/test/fetch/client-fetch.js b/test/fetch/client-fetch.js index 2e7c8c7d8b7..a701f497537 100644 --- a/test/fetch/client-fetch.js +++ b/test/fetch/client-fetch.js @@ -370,7 +370,7 @@ test('locked blob body', (t, done) => { const res = await fetch(`http://localhost:${server.address().port}`) const reader = res.body.getReader() res.blob().catch(err => { - strictEqual(err.message, 'Body is unusable') + strictEqual(err.message, 'Body is unusable: Body has already been read') reader.cancel() }).finally(done) }) @@ -390,7 +390,7 @@ test('disturbed blob body', (t, done) => { ok(true) }) await res.blob().catch(err => { - strictEqual(err.message, 'Body is unusable') + strictEqual(err.message, 'Body is unusable: Body has already been read') }) done() }) diff --git a/test/node-fetch/main.js b/test/node-fetch/main.js index 3ba4a929af0..6b19c3eb4be 100644 --- a/test/node-fetch/main.js +++ b/test/node-fetch/main.js @@ -1385,7 +1385,7 @@ describe('node-fetch', () => { assert.strictEqual(res.headers.get('content-type'), 'text/plain') return res.text().then(() => { assert.strictEqual(res.bodyUsed, true) - return assert.rejects(res.text(), new TypeError('Body is unusable')) + return assert.rejects(res.text(), new TypeError('Body is unusable: Body has already been read')) }) }) })