Skip to content

Commit

Permalink
fetch: Change wording of "Body is unusable" error (#3105)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas authored Apr 20, 2024
1 parent ead42cd commit 437732a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/web/fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ async function consumeBody (object, convertBytesToJSValue, instance, shouldClone
// 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])
Expand Down
4 changes: 2 additions & 2 deletions test/fetch/client-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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()
})
Expand Down
2 changes: 1 addition & 1 deletion test/node-fetch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})
})
})
Expand Down

0 comments on commit 437732a

Please sign in to comment.