From 716e487038fca364648f61c6c432063f1d2c41c0 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 20 Apr 2016 01:26:45 +0200 Subject: [PATCH 1/2] Fixing handling of compression errors --- lib/adapters/http.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 3c3970a..8e4558a 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -103,6 +103,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 d = Buffer.concat(responseBuffer); if (config.responseType !== 'arraybuffer') { From 600653e293e94bcc039f0fb29cde55826407d755 Mon Sep 17 00:00:00 2001 From: Nick Uraltsev Date: Wed, 18 May 2016 19:47:12 -0700 Subject: [PATCH 2/2] Adding test for compression error handling --- test/unit/adapters/http.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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('ж');