Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
Improved error handling in stream and HTTP client.
Browse files Browse the repository at this point in the history
  • Loading branch information
pgriess committed Aug 9, 2010
1 parent 0f57020 commit d45951d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/websocket.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ var WebSocket = function(url, proto) {
self.emit('fd', fd); 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 // External API
self.close = function() { self.close = function() {
switch (readyState) { switch (readyState) {
Expand Down Expand Up @@ -513,10 +524,12 @@ var WebSocket = function(url, proto) {
} }
}); });
stream.addListener('fd', fdListener); stream.addListener('fd', fdListener);
stream.addListener('error', errorListener);


stream.emit('data', head); stream.emit('data', head);
}; };
})()); })());
httpClient.addListener('error', errorListener);


var httpReq = httpClient.request(httpPath, httpHeaders); var httpReq = httpClient.request(httpPath, httpHeaders);


Expand Down

0 comments on commit d45951d

Please sign in to comment.