Skip to content

Commit

Permalink
ENH: added error events
Browse files Browse the repository at this point in the history
  • Loading branch information
srossross committed Sep 15, 2013
1 parent 29afab4 commit 1b867a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/caronte/passes/web-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ function stream(req, res, options) {
common.setupOutgoing(options.ssl || {}, options, req)
);

proxyReq.on('error', function(err){
var ev = 'caronte:outgoing:web:';
if (options.ee.listeners(ev + 'error').length == 0){
throw err;
}
options.ee.emit(ev + 'error', err, req, res);
});

req.pipe(proxyReq);

proxyReq.on('response', function(proxyRes) {
Expand Down
7 changes: 7 additions & 0 deletions lib/caronte/passes/ws-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ function stream(req, socket, options, head) {
var proxyReq = (~['https:', 'wss:'].indexOf(options.target.protocol) ? https : http).request(
common.setupOutgoing(options.ssl || {}, options, req)
);
proxyReq.on('error', function(err){
var ev = 'caronte:outgoing:ws:';
if (options.ee.listeners(ev + 'error').length == 0){
throw err;
}
options.ee.emit(ev + 'error', err, req, res);
});

proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
common.setupSocket(proxySocket);
Expand Down

0 comments on commit 1b867a7

Please sign in to comment.