Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: Change wording of "Body is unusable" error #3105

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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