From c65065ac0f3f1af3986e881bc197362621fd550c Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Thu, 15 Mar 2018 22:12:42 -0700 Subject: [PATCH] capture errors on request data streams --- lib/adapters/http.js | 4 +++- test/unit/adapters/http.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index f081d49..0fe6a7d 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -233,7 +233,9 @@ module.exports = function httpAdapter(config) { // Send the request if (utils.isStream(data)) { - data.pipe(req); + data.on('error', function handleStreamError(err) { + reject(enhanceError(err, config, null, req)); + }).pipe(req); } else { req.end(data); } diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 11144cf..a661563 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -268,6 +268,21 @@ module.exports = { }); }, + testFailedStream: function(test) { + server = http.createServer(function (req, res) { + req.pipe(res); + }).listen(4444, function () { + axios.post('http://localhost:4444/', + fs.createReadStream('/does/not/exist') + ).then(function (res) { + test.fail(); + }).catch(function (err) { + test.equal(err.message, 'ENOENT: no such file or directory, open \'/does/not/exist\''); + test.done(); + }); + }); + }, + testBuffer: function(test) { var buf = new Buffer(1024); // Unsafe buffer < Buffer.poolSize (8192 bytes) buf.fill('x');