smoak / njabbr

Node.js Jabbr.net client
4 stars 7 forks source link

Cannot read property 'responseText' of undefined #10

Open kvarv opened 10 years ago

kvarv commented 10 years ago

[08:26:01 GMT+0200 (W. Europe Daylight Time)] SignalR: Triggering client hub event 'outOfSync' on hub 'Chat'. .... .... [08:26:09 GMT+0200 (W. Europe Daylight Time)] SignalR: Triggering client hub event 'outOfSync' on hub 'Chat'. [08:26:09 GMT+0200 (W. Europe Daylight Time)] SignalR: An error occurred using longPolling. [08:26:09 GMT+0200 (W. Europe Daylight Time)] SignalR: An error ocurred [08:26:09 GMT+0200 (W. Europe Daylight Time)] SignalR: SignalR: Initializing long polling connection with server.

TypeError: Cannot read property 'responseText' of undefined at C:\hubot\node_modules\hubot-jabbr\node_modules\njabbr\lib\transports\common.js:60:66 at Request._callback (C:\hubot\node_modules\hubot-jabbr\node_modules\njabbr\lib\httpUtil.js:21:9) at self.callback (C:\hubot\node_modules\hubot-jabbr\node_modules\njabbr\node_modules\request\request.js:129:22) at Request.EventEmitter.emit (events.js:95:17) at ClientRequest.self.clientErrorHandler (C:\hubot\node_modules\hubot-jabbr\node_modules\njabbr\node_modules\request\r equest.js:239:10) at ClientRequest.EventEmitter.emit (events.js:95:17) at Socket.socketErrorListener (http.js:1547:9) at Socket.EventEmitter.emit (events.js:95:17) at net.js:440:14 at process._tickCallback (node.js:419:13)

I'm using the latest version of JabbR, Hubot 2.6.5, lastest of hubot-jabbr, latest of njabbr with version 2.27.0 of Request.

Any ideas of how to fix this?

smoak commented 10 years ago

Can you try to apply this patch and see if it resolves? I don't have a Windows box to test against the latest version of JabbR, so I've been using jabbr.net and do not get your error.

diff --git lib/transports/common.js lib/transports/common.js
index a82fa48..a6418d5 100644
--- lib/transports/common.js
+++ lib/transports/common.js
@@ -50,14 +50,24 @@
         , url = baseUrl + connection.appRelativeUrl + "/ping"
         , deferral = new Deferred();

-      httpUtils.get(url, function(data) {
-        if (data.Response === "pong") {
-          deferral.resolve();
+      httpUtils.makeHttpRequest({ uri: url, method: "GET" }, function(error, response, body) {
+        if (!error && response.statusCode == 200) {
+          var data;
+          try {
+            data = JSON.parse(body);
+          } catch (error) {
+            deferral.reject("SignalR: Ping server failed");
+          }
+          if (data.Response === "pong") {
+            deferral.resolve();
+          } else {
+            deferral.reject("SignalR: Ping server failed with an invalid response");
+          }
+        } else if (response.statusCode == 401 || response.statusCode == 403) {
+          deferral.reject("SignalR: Ping server failed with a bad status code");
         } else {
-          deferral.reject("SignalR: Invalid ping response when pinging server: " + (data.responseText || data.statusText));
+          deferral.reject("SignalR: Ping server failed");
         }
-      }, function(data) {
-        deferral.reject("SignalR: Error pinging server: " + (data.responseText || data.statusText));
       });

       return deferral.promise();