From 53b5afd3f60a6d90db4e2eb6078bfa88b37ac991 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 10 Apr 2017 21:54:24 +0200 Subject: [PATCH] Fixes #1 - Handle request error events. --- cometd-nodejs-client.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/cometd-nodejs-client.js b/cometd-nodejs-client.js index 1dcee2a..6d1b58e 100644 --- a/cometd-nodejs-client.js +++ b/cometd-nodejs-client.js @@ -81,17 +81,13 @@ module.exports = { } }); }); - _request.on('abort', function() { - self.readyState = window.XMLHttpRequest.DONE; - if (self.onerror) { - self.onerror(); - } - }); - _request.on('aborted', function() { - self.readyState = window.XMLHttpRequest.DONE; - if (self.onerror) { - self.onerror(); - } + ['abort', 'aborted', 'error'].forEach(function(event) { + _request.on(event, function() { + self.readyState = window.XMLHttpRequest.DONE; + if (self.onerror) { + self.onerror(); + } + }); }); if (data) { _request.write(data);