From 62bcf7e1c84ed720bc17435c40e1f78c50ba194c Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 25 Jun 2014 08:53:34 +0200 Subject: [PATCH] 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 --- bin/webdriver-manager | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/webdriver-manager b/bin/webdriver-manager index 033631680..e413c5d5c 100755 --- a/bin/webdriver-manager +++ b/bin/webdriver-manager @@ -111,9 +111,9 @@ var resolveProxy = function(fileUrl) { if (argv.proxy) { return argv.proxy; } else if (protocol === 'https:') { - return process.env.HTTPS_PROXY || process.env.HTTP_PROXY; + return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy; } else if (protocol === 'http:') { - return process.env.HTTP_PROXY; + return process.env.HTTP_PROXY || process.env.http_proxy; } }; @@ -132,8 +132,15 @@ var httpGetFile = function(fileUrl, fileName, outputDir, callback) { proxy: resolveProxy(fileUrl) } request(options, function (error, response) { + if (error) { + fs.unlink(filePath); + console.error('Error: Got error ' + error + ' from ' + fileUrl); + return; + } if (response.statusCode !== 200) { - throw new Error('Got code ' + response.statusCode + ' from ' + fileUrl); + fs.unlink(filePath); + console.error('Error: Got code ' + response.statusCode + ' from ' + fileUrl); + return; } console.log(fileName + ' downloaded to ' + filePath); if (callback) {