From daad4703f3a80014936c89f4d67affdc3246f478 Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Tue, 28 Jan 2014 12:32:43 -0500 Subject: [PATCH] [fix] replicate node core behavior and throw an error if the user does not add their own error listener --- lib/http-proxy/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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); };