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

Commit 1845f2b

Browse files
committed
feat: signal error on reponse stream if x-stream-error
1 parent 843e699 commit 1845f2b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/utils/request-api.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ function onRes (buffer, cb) {
4848
// Return a stream of JSON objects
4949
if (chunkedObjects && isJson) {
5050
const outputStream = pump(res, ndjson.parse())
51+
// TODO: This needs reworking.
52+
// this is a chicken and egg problem -
53+
// 1) we can't get Trailer headers unless the response ends
54+
// 2) we can't propagate the error, because the response stream
55+
// is closed
56+
// (perhaps we can workaround this using pull-streams)
5157
res.on('end', () => {
5258
let err = res.trailers['x-stream-error']
5359
if (err) {
5460
err = JSON.parse(err)
5561
const error = new Error(`Server responded with 500`)
5662
error.code = err.Code
5763
error.message = err.Message
58-
throw error
64+
outputStream.destroy(error) // error is not going to be propagated
5965
}
6066
})
6167
return cb(null, outputStream)

0 commit comments

Comments
 (0)