Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 62bcf7e

Browse files
nwinklerhankduan
authored andcommitted
feat(webdriver-manager): minor proxy enhancements
Added error handling for request - previously, any errors coming from the request module were silently swallowed. Fixed error handling to remove empty files when a download fails for some reason. Instead of throwing an error as an exception, the error is simply logged and then the rest of the code continues. Previously, the uncaught exceptions caused the program to stop immediately, without any chance of recovering, or finishing other downloads. With the previous code, any other downloads at the same time were interrupted, resulting in empty files or incomplete downloads. Logging the errors instead of throwing will allow the other downloads to finish, and it will also allow removing empty files resulting from a failed download, e.g. when no internet connection is available or with an invalid proxy configuration. Also evaluating both uppercase and lowercase proxy variables. Many tools use proxy variables in the form https_proxy, others use HTTPS_PROXY. I changed the code so both forms are evaluated. See the following links for more info on this practice: * http://serverfault.com/q/571887/140074 * https://wiki.archlinux.org/index.php/proxy_settings#Environment_variables
1 parent dbf7ab5 commit 62bcf7e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: bin/webdriver-manager

+10-3
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ var resolveProxy = function(fileUrl) {
111111
if (argv.proxy) {
112112
return argv.proxy;
113113
} else if (protocol === 'https:') {
114-
return process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
114+
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
115115
} else if (protocol === 'http:') {
116-
return process.env.HTTP_PROXY;
116+
return process.env.HTTP_PROXY || process.env.http_proxy;
117117
}
118118
};
119119

@@ -132,8 +132,15 @@ var httpGetFile = function(fileUrl, fileName, outputDir, callback) {
132132
proxy: resolveProxy(fileUrl)
133133
}
134134
request(options, function (error, response) {
135+
if (error) {
136+
fs.unlink(filePath);
137+
console.error('Error: Got error ' + error + ' from ' + fileUrl);
138+
return;
139+
}
135140
if (response.statusCode !== 200) {
136-
throw new Error('Got code ' + response.statusCode + ' from ' + fileUrl);
141+
fs.unlink(filePath);
142+
console.error('Error: Got code ' + response.statusCode + ' from ' + fileUrl);
143+
return;
137144
}
138145
console.log(fileName + ' downloaded to ' + filePath);
139146
if (callback) {

0 commit comments

Comments
 (0)