handle possible readable body error
This commit is contained in:
parent
4b9a1f07ee
commit
f6557b7610
8
index.js
8
index.js
|
@ -380,7 +380,13 @@ function setDefaults(defs) {
|
||||||
if ('function' === typeof _body.pipe) {
|
if ('function' === typeof _body.pipe) {
|
||||||
// used for chunked encoding
|
// used for chunked encoding
|
||||||
_body.pipe(req);
|
_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 {
|
} else {
|
||||||
// used for known content-length
|
// used for known content-length
|
||||||
req.end(_body);
|
req.end(_body);
|
||||||
|
|
Loading…
Reference in New Issue