Skip to content

Commit 0da36b5

Browse files
committed
Improved Proxy error.
1 parent 2e045f0 commit 0da36b5

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

utils.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,24 @@ ProxyAgent.prototype.createSocket = function(options, callback) {
689689
if (res.statusCode === 200) {
690690
callback(socket);
691691
} else {
692-
var err = new Error('Proxy could not be established, code: ' + res.statusCode);
692+
var err = new Error('Proxy could not be established (maybe a problem in auth), code: ' + res.statusCode);
693693
err.code = 'ECONNRESET';
694694
options.request.emit('error', err);
695+
req.destroy && req.destroy();
696+
req = null;
697+
self.requests = null;
698+
self.options = null;
695699
}
696700
});
697701

698702
req.on('error', function(err) {
699-
options.request.emit('error', err);
703+
var e = new Error('Request Proxy "proxy {0} --> target {1}": {2}'.format(PROXYOPTIONS.host + ':' + proxy.port, PROXYOPTIONS.path, err.toString()));
704+
e.code = err.code;
705+
options.request.emit('error', e);
706+
req.destroy && req.destroy();
707+
req = null;
708+
self.requests = null;
709+
self.options = null;
700710
});
701711

702712
req.end();

0 commit comments

Comments
 (0)