From f6557b76102b4d7eaea491a1025988d9634a7abe Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 28 Apr 2020 22:56:12 -0600 Subject: [PATCH] handle possible readable body error --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2d1ee51..ca2654e 100644 --- a/index.js +++ b/index.js @@ -380,7 +380,13 @@ function setDefaults(defs) { if ('function' === typeof _body.pipe) { // used for chunked encoding _body.pipe(req); - _body.on('error', cb); + _body.on('error', function(err) { + // https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options + // if the Readable stream emits an error during processing, + // the Writable destination is not closed automatically + _body.destroy(); + req.destroy(err); + }); } else { // used for known content-length req.end(_body);