@@ -33,7 +33,7 @@ function onRes (buffer, cb) {
33
33
const stream = Boolean ( res . headers [ 'x-stream-output' ] )
34
34
const chunkedObjects = Boolean ( res . headers [ 'x-chunked-output' ] )
35
35
const isJson = res . headers [ 'content-type' ] &&
36
- res . headers [ 'content-type' ] . indexOf ( 'application/json' ) === 0
36
+ res . headers [ 'content-type' ] . indexOf ( 'application/json' ) === 0
37
37
38
38
if ( res . statusCode >= 400 || ! res . statusCode ) {
39
39
return parseError ( res , cb )
@@ -47,28 +47,16 @@ function onRes (buffer, cb) {
47
47
// Return a stream of JSON objects
48
48
if ( chunkedObjects && isJson ) {
49
49
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)
56
50
res . on ( 'end' , ( ) => {
57
51
let err = res . trailers [ 'x-stream-error' ]
58
52
if ( err ) {
59
53
// Not all errors are JSON
60
54
try {
61
55
err = JSON . parse ( err )
62
56
} catch ( e ) {
63
- err = {
64
- Code : 'n/a' ,
65
- Message : err
66
- }
57
+ err = { Message : err }
67
58
}
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 ) )
72
60
}
73
61
} )
74
62
return cb ( null , outputStream )
0 commit comments