Skip to content

Commit daad470

Browse files
committed
[fix] replicate node core behavior and throw an error if the user does not add their own error listener
1 parent b606735 commit daad470

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/http-proxy/index.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function createRightProxy(type) {
6868
if (typeof options[e] === 'string')
6969
options[e] = parse_url(options[e]);
7070
});
71-
71+
7272
if(typeof this.emit === 'undefined' && !cbl) { throw new Error("You need to pass a callback to handle errors") }
7373

7474
for(var i=0; i < passes.length; i++) {
@@ -104,13 +104,22 @@ function ProxyServer(options) {
104104
return ws[pass];
105105
});
106106

107-
this.on('error', function(err) {
108-
console.log(err);
109-
});
107+
this.on('error', this.onError.bind(this));
108+
110109
}
111110

112111
require('util').inherits(ProxyServer, EE3);
113112

113+
ProxyServer.prototype.onError = function (err) {
114+
//
115+
// Remark: Replicate node core behavior using EE3
116+
// so we force people to handle their own errors
117+
//
118+
if(this.listeners('error').length === 1) {
119+
throw err;
120+
}
121+
};
122+
114123
ProxyServer.prototype.listen = function(port, hostname) {
115124
var self = this,
116125
closure = function(req, res) { self.web(req, res); };

0 commit comments

Comments
 (0)