Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit bde2489

Browse files
committed
fix: propagate trailer errors correctly
1 parent 447f362 commit bde2489

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/utils/send-files-stream.js

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ module.exports = (send, path) => {
123123
return retStream.push(null) // early
124124
}
125125

126+
response.on('error', (err) => retStream.emit('error', err))
127+
126128
if (!isStream(response)) {
127129
retStream.push(response)
128130
retStream.push(null)

src/utils/send-request.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,16 @@ function onRes (buffer, cb) {
4747
// Return a stream of JSON objects
4848
if (chunkedObjects && isJson) {
4949
const outputStream = pump(res, ndjson.parse())
50-
// TODO: This needs reworking.
51-
// this is a chicken and egg problem -
52-
// 1) we can't get Trailer headers unless the response ends
53-
// 2) we can't propagate the error, because the response stream
54-
// is closed
55-
// (perhaps we can workaround this using pull-streams)
5650
res.on('end', () => {
5751
let err = res.trailers['x-stream-error']
5852
if (err) {
5953
// Not all errors are JSON
6054
try {
6155
err = JSON.parse(err)
6256
} catch (e) {
63-
err = {
64-
Code: 'n/a',
65-
Message: err
66-
}
57+
err = { Message: err }
6758
}
68-
const error = new Error(`Server responded with 500`)
69-
error.code = err.Code
70-
error.message = err.Message
71-
outputStream.destroy(error) // error is not going to be propagated
59+
outputStream.emit('error', new Error(err.Message))
7260
}
7361
})
7462
return cb(null, outputStream)

0 commit comments

Comments
 (0)