Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved error handling in stream and HTTP client.

  • Loading branch information...
commit d45951d3648451addf754da07a31e9fa298b3d8e 1 parent 0f57020
@pgriess authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 lib/websocket.js
View
13 lib/websocket.js
@@ -314,6 +314,17 @@ var WebSocket = function(url, proto) {
self.emit('fd', fd);
};
+ // Handle errors from any source (HTTP client, stream, etc)
+ var errorListener = function(e) {
+ process.nextTick(function() {
+ self.emit('wserror', e);
+
+ if (self.onerror) {
+ self.onerror(e);
+ }
+ });
+ };
+
// External API
self.close = function() {
switch (readyState) {
@@ -513,10 +524,12 @@ var WebSocket = function(url, proto) {
}
});
stream.addListener('fd', fdListener);
+ stream.addListener('error', errorListener);
stream.emit('data', head);
};
})());
+ httpClient.addListener('error', errorListener);
var httpReq = httpClient.request(httpPath, httpHeaders);
Please sign in to comment.
Something went wrong with that request. Please try again.