diff --git a/lib/adapters/http.js b/lib/adapters/http.js index f081d49e143faa7c4c011cb2af9a524343745a05..0fe6a7dc79fbd843050ca8a081071378f8306160 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 11144cf62eb28a0c3fc13e078db420173b50f2be..a661563a827248f8e0499c97ecae815062f3fc7c 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');