Skip to content

Commit 674875a

Browse files
authored
feat(fetch): better errors messages for body-mixin methods (nodejs#1654)
1 parent dcd4e81 commit 674875a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/fetch/body.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ function safelyExtractBody (object, keepalive = false) {
230230
if (object instanceof ReadableStream) {
231231
// Assert: object is neither disturbed nor locked.
232232
// istanbul ignore next
233-
assert(!util.isDisturbed(object), 'disturbed')
233+
assert(!util.isDisturbed(object), 'The body has already been consumed.')
234234
// istanbul ignore next
235-
assert(!object.locked, 'locked')
235+
assert(!object.locked, 'The stream is locked.')
236236
}
237237

238238
// 2. Return the results of extracting object.
@@ -266,11 +266,11 @@ async function * consumeBody (body) {
266266
const stream = body.stream
267267

268268
if (util.isDisturbed(stream)) {
269-
throw new TypeError('disturbed')
269+
throw new TypeError('The body has already been consumed.')
270270
}
271271

272272
if (stream.locked) {
273-
throw new TypeError('locked')
273+
throw new TypeError('The stream is locked.')
274274
}
275275

276276
// Compat.

test/fetch/client-fetch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ test('locked blob body', (t) => {
250250
const res = await fetch(`http://localhost:${server.address().port}`)
251251
const reader = res.body.getReader()
252252
res.blob().catch(err => {
253-
t.equal(err.message, 'locked')
253+
t.equal(err.message, 'The stream is locked.')
254254
reader.cancel()
255255
})
256256
})
@@ -270,7 +270,7 @@ test('disturbed blob body', (t) => {
270270
t.pass(2)
271271
})
272272
res.blob().catch(err => {
273-
t.equal(err.message, 'disturbed')
273+
t.equal(err.message, 'The body has already been consumed.')
274274
})
275275
})
276276
})

0 commit comments

Comments
 (0)