From 1b867a7f594f7dfe49fc17ff53451a353ec509d9 Mon Sep 17 00:00:00 2001 From: srossross Date: Sun, 15 Sep 2013 15:20:51 -0700 Subject: [PATCH] ENH: added error events --- lib/caronte/passes/web-incoming.js | 8 ++++++++ lib/caronte/passes/ws-incoming.js | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/lib/caronte/passes/web-incoming.js b/lib/caronte/passes/web-incoming.js index 6906ae8..66beb01 100644 --- a/lib/caronte/passes/web-incoming.js +++ b/lib/caronte/passes/web-incoming.js @@ -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) { diff --git a/lib/caronte/passes/ws-incoming.js b/lib/caronte/passes/ws-incoming.js index 1fd3fd7..3b5e1f5 100644 --- a/lib/caronte/passes/ws-incoming.js +++ b/lib/caronte/passes/ws-incoming.js @@ -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);