From f8a4cea4feca1c949d50baae6c6ed1ea649a2b9d Mon Sep 17 00:00:00 2001 From: Enrico Stara Date: Mon, 10 Nov 2014 16:38:01 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Give=20to=20FF=20a=20chance=20to=20set=20th?= =?UTF-8?q?e=20=E2=80=98xhr.responseType=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/request.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/request.js b/lib/request.js index 7b8b733..c94430b 100644 --- a/lib/request.js +++ b/lib/request.js @@ -22,15 +22,15 @@ var Request = module.exports = function (xhr, params) { try { xhr.withCredentials = params.withCredentials } catch (e) {} - if (params.responseType) try { xhr.responseType = params.responseType } - catch (e) {} - xhr.open( params.method || 'GET', self.uri, true ); + if (params.responseType) try { xhr.responseType = params.responseType } + catch (e) {} + xhr.onerror = function(event) { self.emit('error', new Error('Network error')); }; From 0adc0808fe1b2c94a1ecf8298440c13926e1be9a Mon Sep 17 00:00:00 2001 From: Enrico Stara Date: Tue, 25 Nov 2014 16:15:28 +0100 Subject: [PATCH 2/2] Check first if the response body is defined --- lib/response.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/response.js b/lib/response.js index f83d761..d1e68e4 100644 --- a/lib/response.js +++ b/lib/response.js @@ -104,12 +104,12 @@ Response.prototype.handle = function (res) { Response.prototype._emitData = function (res) { var respBody = this.getResponse(res); - if (respBody.toString().match(/ArrayBuffer/)) { + if (respBody && respBody.toString().match(/ArrayBuffer/)) { this.emit('data', new Uint8Array(respBody, this.offset)); this.offset = respBody.byteLength; return; } - if (respBody.length > this.offset) { + if (respBody && respBody.length > this.offset) { this.emit('data', respBody.slice(this.offset)); this.offset = respBody.length; }