Skip to content
Permalink
Browse files

[fix] replicate node core behavior and throw an error if the user doe…

…s not add their own error listener
  • Loading branch information...
jcrugzz committed Jan 28, 2014
1 parent b606735 commit daad4703f3a80014936c89f4d67affdc3246f478
Showing with 13 additions and 4 deletions.
  1. +13 −4 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); };

6 comments on commit daad470

@3rd-Eden

This comment has been minimized.

Copy link
Contributor

replied Jan 28, 2014

Yes, because crashing servers because your missing an error listener is the right thing to do™ ;)

@jcrugzz

This comment has been minimized.

Copy link
Contributor Author

replied Jan 28, 2014

@3rd-Eden its a teaching mechanism ;)

@3rd-Eden

This comment has been minimized.

Copy link
Contributor

replied Jan 28, 2014

@jcrugzz there nothing wrong with teaching people this during development, but not in production ;-)

@glasser

This comment has been minimized.

Copy link
Contributor

replied Jan 28, 2014

I mean, it sure beats a console.log that you can't control!

@yawnt

This comment has been minimized.

Copy link
Contributor

replied Jan 28, 2014

yeah i'm not sure why i even wrote that.. @glasser i apologize for not paying enough attention in the past few days but college finals are coming up. please refer to @jcrugzz for the next couple of weeks :)

@glasser

This comment has been minimized.

Copy link
Contributor

replied Jan 29, 2014

No worries @yawnt, glad to see caronte out and happy to use it! Good luck on finals!

Please sign in to comment.
You can’t perform that action at this time.