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

[WIP] fix: propagate trailer errors correctly #636

Merged
merged 2 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ environment:
- nodejs_version: "6"
- nodejs_version: "8"

init:
- git config --global core.autocrlf input

# cache:
# - node_modules

Expand Down
2 changes: 2 additions & 0 deletions src/utils/send-files-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ module.exports = (send, path) => {
return
}

response.on('error', (err) => retStream.emit('error', err))

response.on('data', (d) => {
if (d.Bytes && options.progress) {
options.progress(d.Bytes)
Expand Down
16 changes: 2 additions & 14 deletions src/utils/send-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,16 @@ function onRes (buffer, cb) {
// Return a stream of JSON objects
if (chunkedObjects && isJson) {
const outputStream = pump(res, ndjson.parse())
// TODO: This needs reworking.
// this is a chicken and egg problem -
// 1) we can't get Trailer headers unless the response ends
// 2) we can't propagate the error, because the response stream
// is closed
// (perhaps we can workaround this using pull-streams)
res.on('end', () => {
let err = res.trailers['x-stream-error']
if (err) {
// Not all errors are JSON
try {
err = JSON.parse(err)
} catch (e) {
err = {
Code: 'n/a',
Message: err
}
err = { Message: err }
}
const error = new Error(`Server responded with 500`)
error.code = err.Code
error.message = err.Message
outputStream.destroy(error) // error is not going to be propagated
outputStream.emit('error', new Error(err.Message))
}
})
return cb(null, outputStream)
Expand Down