I'm not sure if I'm looking at this wrong, but if I specify a stream as the request body, and that stream errors, I can't see how to receive the error from the request body stream.
Take a look at the following test:
const { PassThrough } = require('stream')
it('should propagate errors from streaming bodies', async () => {
const body = new PassThrough()
const err = new Error('Aargh!')
const req = fetch('https://example.com', {
method: 'POST',
body
})
// the request body failed, for whatever reason
body.emit(err)
// have to end the stream after the error otherwise `await req` below does not resolve
body.end()
try {
// should something here throw with the request body error?
const res = await req
await res.text()
throw new Error('What happened to err?')
} catch (e) {
expect(e.message).to.equal(err.message)
}
})
1) should propagate errors from streaming bodies:
AssertionError: expected 'What happened to err?' to equal 'Aargh!'
+ expected - actual
-What happened to err?
+Aargh!
The await res.text() returns the response from the server as if nothing went wrong when actually the request body was truncated.
At the moment it looks like I need to set up the error listener on the request body stream externally, along with an AbortController and kill the request manually if the request body errors which adds a whole load of boilerplate to my codebase.
I'm not sure if I'm looking at this wrong, but if I specify a stream as the request body, and that stream errors, I can't see how to receive the error from the request body stream.
Take a look at the following test:
The
await res.text()returns the response from the server as if nothing went wrong when actually the request body was truncated.At the moment it looks like I need to set up the error listener on the request body stream externally, along with an AbortController and kill the request manually if the request body errors which adds a whole load of boilerplate to my codebase.