Skip to content

Commit

Permalink
fetch: Change wording of "Body is unusable" error
Browse files Browse the repository at this point in the history
fixes #3097
  • Loading branch information
nzakas committed Apr 12, 2024
1 parent 8f192e3 commit aab7a21
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 @@ -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])
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 aab7a21

Please sign in to comment.