mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix: capture errors on request data streams
This commit is contained in:
@@ -233,7 +233,9 @@ module.exports = function httpAdapter(config) {
|
|||||||
|
|
||||||
// Send the request
|
// Send the request
|
||||||
if (utils.isStream(data)) {
|
if (utils.isStream(data)) {
|
||||||
data.pipe(req);
|
data.on('error', function handleStreamError(err) {
|
||||||
|
reject(enhanceError(err, config, null, req));
|
||||||
|
}).pipe(req);
|
||||||
} else {
|
} else {
|
||||||
req.end(data);
|
req.end(data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
testBuffer: function(test) {
|
||||||
var buf = new Buffer(1024); // Unsafe buffer < Buffer.poolSize (8192 bytes)
|
var buf = new Buffer(1024); // Unsafe buffer < Buffer.poolSize (8192 bytes)
|
||||||
buf.fill('x');
|
buf.fill('x');
|
||||||
|
|||||||
Reference in New Issue
Block a user