Permalink
Browse files

Catch and log errors that occur while raising the received event.

Added sample to demohub.
  • Loading branch information...
1 parent f62b0e5 commit 3de16b19a464eb2ad65dfc59b59b1fd6327e9dcc @davidfowl davidfowl committed Aug 31, 2011
@@ -19,6 +19,10 @@ public class DemoHub : Hub {
Caller.groupAdded();
}
+ public void DoSomethingAndCallError() {
+ Clients.errorInCallback();
+ }
+
public Task DynamicTask() {
return Clients.signal(Guid.NewGuid());
}
@@ -17,7 +17,14 @@
$('#groupAdded').append('Group Added');
};
+ demo.errorInCallback = function () {
+ var o = null;
+ o.doIt();
+ };
+
$.connection.hub.start(function () {
+ demo.doSomethingAndCallError();
+
demo.getValue(function (value) {
$('#value').html('The value is ' + value + ' after 5 seconds');
});
@@ -207,7 +207,7 @@
start: function (connection, onSuccess, onFailed) {
var url,
opened = false;
-
+
if (window.MozWebSocket) {
window.WebSocket = window.MozWebSocket;
}
@@ -301,7 +301,14 @@
if (data) {
if (data.Messages) {
$.each(data.Messages, function () {
- $(instance).trigger("onReceived", [this]);
+ try {
+ $(instance).trigger("onReceived", [this]);
+ }
+ catch (e) {
+ if (console && console.log) {
+ console.log('Error raising received ' + e);
+ }
+ }
});
}
instance.messageId = data.MessageId;
@@ -330,10 +337,13 @@
}, 2 * 1000);
}
});
- }(connection));
+ } (connection));
// Now connected
- onSuccess();
+ // There's no good way know when the long poll has actually started so
+ // we and assume it only takes around 150ms (max) to start connection
+ // to start.
+ setTimeout(onSuccess, 150);
}, 250); // Have to delay initial poll so Chrome doesn't show loader spinner in tab
},
@@ -391,4 +401,4 @@
$.connection = $.signalR = signalR;
-}(window.jQuery, window));
+} (window.jQuery, window));

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -207,7 +207,7 @@
start: function (connection, onSuccess, onFailed) {
var url,
opened = false;
-
+
if (window.MozWebSocket) {
window.WebSocket = window.MozWebSocket;
}
@@ -301,7 +301,14 @@
if (data) {
if (data.Messages) {
$.each(data.Messages, function () {
- $(instance).trigger("onReceived", [this]);
+ try {
+ $(instance).trigger("onReceived", [this]);
+ }
+ catch (e) {
+ if (console && console.log) {
+ console.log('Error raising received ' + e);
+ }
+ }
});
}
instance.messageId = data.MessageId;
@@ -330,10 +337,13 @@
}, 2 * 1000);
}
});
- }(connection));
+ } (connection));
// Now connected
- onSuccess();
+ // There's no good way know when the long poll has actually started so
+ // we and assume it only takes around 150ms (max) to start connection
+ // to start.
+ setTimeout(onSuccess, 150);
}, 250); // Have to delay initial poll so Chrome doesn't show loader spinner in tab
},
@@ -391,4 +401,4 @@
$.connection = $.signalR = signalR;
-}(window.jQuery, window));
+} (window.jQuery, window));
Oops, something went wrong.

0 comments on commit 3de16b1

Please sign in to comment.