diff --git a/lib/adapters/http.js b/lib/adapters/http.js index f5e40ed..86251aa 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -116,6 +116,11 @@ module.exports = function httpAdapter(resolve, reject, config) { } }); + stream.on('error', function handleStreamError(err) { + if (aborted) return; + reject(err); + }); + stream.on('end', function handleStreamEnd() { var responseData = Buffer.concat(responseBuffer); if (config.responseType !== 'arraybuffer') { diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index acd0b30..9351fcb 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -102,6 +102,18 @@ module.exports = { }); }, + testGunzipErrorHandling: function (test) { + server = http.createServer(function (req, res) { + res.setHeader('Content-Type', 'application/json;charset=utf-8'); + res.setHeader('Content-Encoding', 'gzip'); + res.end('invalid response'); + }).listen(4444, function () { + axios.get('http://localhost:4444/').catch(function (error) { + test.done(); + }); + }); + }, + testUTF8: function (test) { var str = Array(100000).join('ж');