Skip to content

Commit cb63021

Browse files
fix: capture errors on request data streams
2 parents e990a91 + c65065a commit cb63021

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/adapters/http.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ module.exports = function httpAdapter(config) {
233233

234234
// Send the request
235235
if (utils.isStream(data)) {
236-
data.pipe(req);
236+
data.on('error', function handleStreamError(err) {
237+
reject(enhanceError(err, config, null, req));
238+
}).pipe(req);
237239
} else {
238240
req.end(data);
239241
}

test/unit/adapters/http.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,21 @@ module.exports = {
268268
});
269269
},
270270

271+
testFailedStream: function(test) {
272+
server = http.createServer(function (req, res) {
273+
req.pipe(res);
274+
}).listen(4444, function () {
275+
axios.post('http://localhost:4444/',
276+
fs.createReadStream('/does/not/exist')
277+
).then(function (res) {
278+
test.fail();
279+
}).catch(function (err) {
280+
test.equal(err.message, 'ENOENT: no such file or directory, open \'/does/not/exist\'');
281+
test.done();
282+
});
283+
});
284+
},
285+
271286
testBuffer: function(test) {
272287
var buf = new Buffer(1024); // Unsafe buffer < Buffer.poolSize (8192 bytes)
273288
buf.fill('x');

0 commit comments

Comments
 (0)