diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index 994781a9b..9ae68615d 100644 --- a/lib/http-proxy/index.js +++ b/lib/http-proxy/index.js @@ -68,7 +68,7 @@ function createRightProxy(type) { if (typeof options[e] === 'string') options[e] = parse_url(options[e]); }); - + if(typeof this.emit === 'undefined' && !cbl) { throw new Error("You need to pass a callback to handle errors") } for(var i=0; i < passes.length; i++) { @@ -104,13 +104,22 @@ function ProxyServer(options) { return ws[pass]; }); - this.on('error', function(err) { - console.log(err); - }); + this.on('error', this.onError.bind(this)); + } require('util').inherits(ProxyServer, EE3); +ProxyServer.prototype.onError = function (err) { + // + // Remark: Replicate node core behavior using EE3 + // so we force people to handle their own errors + // + if(this.listeners('error').length === 1) { + throw err; + } +}; + ProxyServer.prototype.listen = function(port, hostname) { var self = this, closure = function(req, res) { self.web(req, res); };