browserstack-cypress-cli 1.31.10 → 1.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,9 +8,12 @@ const logger = require('./logger').winstonLogger,
8
8
  Constants = require("./constants"),
9
9
  config = require("./config");
10
10
 
11
- const request = require('request');
11
+ const { default: axios } = require('axios');
12
+ const HttpsProxyAgent = require('https-proxy-agent');
13
+ const FormData = require('form-data');
12
14
  const decompress = require('decompress');
13
15
  const unzipper = require("unzipper");
16
+ const { setAxiosProxy } = require('./helper');
14
17
 
15
18
  let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
16
19
  let BUILD_ARTIFACTS_FAIL_COUNT = 0;
@@ -107,18 +110,23 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
107
110
 
108
111
  logger.debug(`Downloading build artifact for: ${filePath}`)
109
112
  return new Promise(async (resolve, reject) => {
110
- request.get(url).on('response', function(response) {
111
-
112
- if(response.statusCode != 200) {
113
- if (response.statusCode === 404) {
113
+ try {
114
+ const axiosConfig = {
115
+ responseType: 'stream',
116
+ validateStatus: status => (status >= 200 && status < 300) || status === 404
117
+ };
118
+ setAxiosProxy(axiosConfig);
119
+ const response = await axios.get(url, axiosConfig);
120
+ if(response.status != 200) {
121
+ if (response.status === 404) {
114
122
  reject(Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND);
115
123
  }
116
- const errorMsg = `Non 200 status code, got status code: ${response.statusCode}`;
124
+ const errorMsg = `Non 200 status code, got status code: ${response.status}`;
117
125
  reject(errorMsg);
118
126
  } else {
119
127
  //ensure that the user can call `then()` only when the file has
120
128
  //been downloaded entirely.
121
- response.pipe(writer);
129
+ response.data.pipe(writer);
122
130
  let error = null;
123
131
  writer.on('error', err => {
124
132
  error = err;
@@ -137,7 +145,9 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
137
145
  resolve(true);
138
146
  });
139
147
  }
140
- });
148
+ } catch (error) {
149
+ reject(error);
150
+ }
141
151
  });
142
152
  }
143
153
 
@@ -188,28 +198,38 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs, bu
188
198
  }
189
199
 
190
200
  options.formData = data.toString();
201
+ const axiosConfig = {
202
+ auth: {
203
+ username: options.auth.username,
204
+ password: options.auth.password
205
+ },
206
+ headers: options.headers
207
+ };
208
+ setAxiosProxy(axiosConfig);
209
+
191
210
  let responseData = null;
192
211
  return new Promise (async (resolve, reject) => {
193
- request.post(options, function (err, resp, data) {
194
- if(err) {
195
- utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', buildReportData, rawArgs);
196
- logger.error(utils.formatRequest(err, resp, data));
197
- reject(err);
198
- } else {
199
- try {
200
- responseData = JSON.parse(data);
201
- } catch(e) {
202
- responseData = {};
203
- }
204
- if (resp.statusCode != 200) {
205
- if (responseData && responseData["error"]) {
206
- utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', buildReportData, rawArgs);
207
- reject(responseData["error"])
208
- }
212
+ try {
213
+ const response = await axios.post(options.url, data, axiosConfig);
214
+ try {
215
+ responseData = response.data;
216
+ } catch(e) {
217
+ responseData = {};
218
+ }
219
+ if (response.status != 200) {
220
+ if (responseData && responseData["error"]) {
221
+ utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', buildReportData, rawArgs);
222
+ reject(responseData["error"])
209
223
  }
210
224
  }
211
- resolve()
212
- });
225
+ resolve();
226
+ } catch (error) {
227
+ if(error.response) {
228
+ utils.sendUsageReport(bsConfig, args, error.response, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', buildReportData, rawArgs);
229
+ logger.error(utils.formatRequest(error.response.statusText, error.response, error.response.data));
230
+ reject(errror.response.data.message);
231
+ }
232
+ }
213
233
  });
214
234
  }
215
235
 
@@ -235,53 +255,51 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
235
255
  let messageType = null;
236
256
  let errorCode = null;
237
257
  let buildDetails = null;
238
- request.get(options, async function (err, resp, body) {
239
- if(err) {
240
- logger.error(utils.formatRequest(err, resp, body));
241
- utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', buildReportData, rawArgs);
258
+ options.config = {
259
+ auth: options.auth,
260
+ headers: options.headers
261
+ }
262
+ setAxiosProxy(options.config);
263
+ let response;
264
+ try {
265
+ response = await axios.get(options.url, options.config);
266
+ buildDetails = response.data;
267
+ await createDirectories(buildId, buildDetails);
268
+ await parseAndDownloadArtifacts(buildId, buildDetails, bsConfig, args, rawArgs, buildReportData);
269
+ if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
270
+ messageType = Constants.messageTypes.ERROR;
271
+ message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
272
+ logger.error(message);
242
273
  process.exitCode = Constants.ERROR_EXIT_CODE;
243
274
  } else {
244
- try {
245
- buildDetails = JSON.parse(body);
246
- if(resp.statusCode != 200) {
247
- logger.error('Downloading the build artifacts failed.');
248
- logger.error(`Error: Request failed with status code ${resp.statusCode}`)
249
- logger.error(utils.formatRequest(err, resp, body));
250
- utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', buildReportData, rawArgs);
251
- process.exitCode = Constants.ERROR_EXIT_CODE;
252
- } else {
253
- await createDirectories(buildId, buildDetails);
254
- await parseAndDownloadArtifacts(buildId, buildDetails, bsConfig, args, rawArgs, buildReportData);
255
- if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
256
- messageType = Constants.messageTypes.ERROR;
257
- message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
258
- logger.error(message);
259
- process.exitCode = Constants.ERROR_EXIT_CODE;
260
- } else {
261
- messageType = Constants.messageTypes.SUCCESS;
262
- message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
263
- logger.info(message);
264
- }
265
- await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs, buildReportData)
266
- utils.sendUsageReport(bsConfig, args, message, messageType, null, buildReportData, rawArgs);
267
- }
268
- } catch (err) {
275
+ messageType = Constants.messageTypes.SUCCESS;
276
+ message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
277
+ logger.info(message);
278
+ }
279
+ await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs, buildReportData)
280
+ utils.sendUsageReport(bsConfig, args, message, messageType, null, buildReportData, rawArgs);
281
+ } catch (err) {
282
+ messageType = Constants.messageTypes.ERROR;
283
+ errorCode = 'api_failed_build_artifacts';
284
+ if(err.response && err.response.status !== 200) {
285
+ logger.error('Downloading the build artifacts failed.');
286
+ logger.error(`Error: Request failed with status code ${err.response.status}`)
287
+ logger.error(utils.formatRequest(err.response.statusText, err.response, err.response.data));
288
+ utils.sendUsageReport(bsConfig, args, JSON.stringify(buildDetails), Constants.messageTypes.ERROR, 'api_failed_build_artifacts', buildReportData, rawArgs);
289
+ } else {
290
+ if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
269
291
  messageType = Constants.messageTypes.ERROR;
270
- errorCode = 'api_failed_build_artifacts';
271
- if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
272
- messageType = Constants.messageTypes.ERROR;
273
- message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
274
- logger.error(message);
275
- } else {
276
- logger.error('Downloading the build artifacts failed.');
277
- }
278
- utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, buildReportData, rawArgs);
279
- logger.error(`Error: Request failed with status code ${resp.statusCode}`)
280
- logger.error(utils.formatRequest(err, resp, body));
281
- process.exitCode = Constants.ERROR_EXIT_CODE;
292
+ message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
293
+ logger.error(message);
294
+ } else {
295
+ logger.error('Downloading the build artifacts failed.');
282
296
  }
297
+ utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, buildReportData, rawArgs);
298
+ logger.error(`Error: Request failed with status code ${resp.status}`)
299
+ logger.error(utils.formatRequest(err, resp, body));
283
300
  }
284
- resolve();
285
- });
301
+ process.exitCode = Constants.ERROR_EXIT_CODE;
302
+ }
303
+ resolve();
286
304
  });
287
305
  };
@@ -132,6 +132,7 @@ const caps = (bsConfig, zip) => {
132
132
  }
133
133
 
134
134
  obj.cypress_cli_user_agent = Utils.getUserAgent();
135
+
135
136
  logger.info(`Cypress CLI User Agent: ${obj.cypress_cli_user_agent}`);
136
137
 
137
138
  if(obj.parallels === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const request = require('request');
2
+ const { default: axios } = require('axios');
3
3
  const { combineMacWinNpmDependencies } = require('./helper');
4
4
 
5
5
  const crypto = require('crypto'),
@@ -11,6 +11,7 @@ const crypto = require('crypto'),
11
11
  utils = require('./utils'),
12
12
  logger = require('./logger').winstonLogger;
13
13
 
14
+ const { setAxiosProxy } = require('./helper');
14
15
 
15
16
  const checkSpecsMd5 = (runSettings, args, instrumentBlocks) => {
16
17
  return new Promise(function (resolve, reject) {
@@ -91,7 +92,7 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
91
92
  }
92
93
 
93
94
  instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Total");
94
- checkSpecsMd5(bsConfig.run_settings, args, instrumentBlocks).then(function (zip_md5sum) {
95
+ checkSpecsMd5(bsConfig.run_settings, args, instrumentBlocks).then(async function (zip_md5sum) {
95
96
  instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Package");
96
97
  let npm_package_md5sum = checkPackageMd5(bsConfig.run_settings);
97
98
  instrumentBlocks.markBlockEnd("checkAlreadyUploaded.md5Package");
@@ -116,7 +117,7 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
116
117
  'Content-Type': 'application/json',
117
118
  "User-Agent": utils.getUserAgent(),
118
119
  },
119
- body: JSON.stringify(data)
120
+ body: data
120
121
  };
121
122
 
122
123
  if (Constants.turboScaleObj.enabled) {
@@ -124,39 +125,48 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
124
125
  }
125
126
 
126
127
  instrumentBlocks.markBlockStart("checkAlreadyUploaded.railsCheck");
127
- request.post(options, function (err, resp, body) {
128
- if (err) {
129
- instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
130
- resolve(obj);
131
- } else {
132
- let zipData = null;
133
- try {
134
- zipData = JSON.parse(body);
135
- } catch (error) {
136
- zipData = {};
137
- }
138
- if (resp.statusCode === 200) {
139
- if (!utils.isUndefined(zipData.zipUrl)) {
140
- Object.assign(obj, zipData, {zipUrlPresent: true});
141
- }
142
- if (!utils.isUndefined(zipData.npmPackageUrl)) {
143
- Object.assign(obj, zipData, {packageUrlPresent: true});
144
- }
145
- }
146
- if (utils.isTrueString(zipData.disableNpmSuiteCache)) {
147
- bsConfig.run_settings.cache_dependencies = false;
148
- Object.assign(obj, {packageUrlPresent: false});
149
- delete obj.npm_package_md5sum;
128
+
129
+ const axiosConfig = {
130
+ auth: {
131
+ username: options.auth.user,
132
+ password: options.auth.password
133
+ },
134
+ headers: options.headers
135
+ };
136
+ setAxiosProxy(axiosConfig);
137
+
138
+ try {
139
+ const response = await axios.post(options.url, options.body, axiosConfig);
140
+ let zipData = null;
141
+ try {
142
+ zipData = response.data;
143
+ } catch (error) {
144
+ zipData = {};
145
+ }
146
+ if (response.status === 200) {
147
+ if (!utils.isUndefined(zipData.zipUrl)) {
148
+ Object.assign(obj, zipData, {zipUrlPresent: true});
150
149
  }
151
- if (utils.isTrueString(zipData.disableTestSuiteCache)) {
152
- args["force-upload"] = true;
153
- Object.assign(obj, {zipUrlPresent: false});
154
- delete obj.zip_md5sum;
150
+ if (!utils.isUndefined(zipData.npmPackageUrl)) {
151
+ Object.assign(obj, zipData, {packageUrlPresent: true});
155
152
  }
156
- instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
157
- resolve(obj);
158
153
  }
159
- });
154
+ if (utils.isTrueString(zipData.disableNpmSuiteCache)) {
155
+ bsConfig.run_settings.cache_dependencies = false;
156
+ Object.assign(obj, {packageUrlPresent: false});
157
+ delete obj.npm_package_md5sum;
158
+ }
159
+ if (utils.isTrueString(zipData.disableTestSuiteCache)) {
160
+ args["force-upload"] = true;
161
+ Object.assign(obj, {zipUrlPresent: false});
162
+ delete obj.zip_md5sum;
163
+ }
164
+ instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
165
+ resolve(obj);
166
+ } catch (error) {
167
+ instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
168
+ resolve(obj);
169
+ }
160
170
  }).catch((err) => {
161
171
  let errString = err.stack ? err.stack.toString().substring(0,100) : err.toString().substring(0,100);
162
172
  resolve({zipUrlPresent: false, packageUrlPresent: false, error: errString});
@@ -1,28 +1,37 @@
1
- 'use strict'
2
- const request = require('request');
1
+ 'use strict';
2
+ const { default: axios } = require('axios');
3
+ const { setAxiosProxy } = require('./helper');
4
+
5
+ const downloadBuildStacktrace = async (url, bsConfig) => {
6
+ const axiosConfig = {
7
+ auth: {
8
+ username: bsConfig.auth.username,
9
+ password: bsConfig.auth.access_key
10
+ },
11
+ responseType: 'stream',
12
+ };
13
+ setAxiosProxy(axiosConfig);
3
14
 
4
- const downloadBuildStacktrace = async (url) => {
5
15
  return new Promise(async (resolve, reject) => {
6
- request.get(url).on('response', function (response) {
7
- if(response.statusCode == 200) {
8
- response.pipe(process.stdout);
16
+ try {
17
+ const response = await axios.get(url, axiosConfig);
18
+ if (response.status === 200) {
19
+ response.data.pipe(process.stdout);
9
20
  let error = null;
10
21
  process.stdout.on('error', (err) => {
11
22
  error = err;
12
23
  process.stdout.close();
13
- reject(response.statusCode);
24
+ reject(response.status);
14
25
  });
15
26
  process.stdout.on('close', async () => {
16
- if(!error) {
17
- resolve("Build stacktrace downloaded successfully");
27
+ if (!error) {
28
+ resolve('Build stacktrace downloaded successfully');
18
29
  }
19
30
  });
20
- } else {
21
- reject(response.statusCode);
22
31
  }
23
- }).on('end', () => {
24
- resolve("Build stacktrace downloaded successfully");
25
- });
32
+ } catch (error) {
33
+ reject(error.response.status);
34
+ }
26
35
  });
27
36
  };
28
37
 
@@ -1,11 +1,14 @@
1
- const request = require('request'),
2
- logger = require('./logger').winstonLogger,
1
+ const { default: axios } = require('axios');
2
+
3
+ const logger = require('./logger').winstonLogger,
3
4
  utils = require('./utils'),
4
5
  config = require("./config"),
5
6
  Constants = require('./constants');
6
7
 
8
+ const { setAxiosProxy } = require('./helper');
9
+
7
10
  exports.getInitialDetails = (bsConfig, args, rawArgs) => {
8
- return new Promise((resolve, reject) => {
11
+ return new Promise(async (resolve, reject) => {
9
12
  let options = {
10
13
  url: config.getInitialDetails,
11
14
  auth: {
@@ -17,28 +20,36 @@ exports.getInitialDetails = (bsConfig, args, rawArgs) => {
17
20
  }
18
21
  };
19
22
  let responseData = {};
20
- request.get(options, function (err, resp, data) {
21
- if(err) {
22
- logger.warn(utils.formatRequest(err, resp, data));
23
- utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
23
+
24
+ const axiosConfig = {
25
+ auth: options.auth,
26
+ headers: options.headers,
27
+ }
28
+ setAxiosProxy(axiosConfig);
29
+
30
+ try {
31
+ const response = await axios.get(options.url, axiosConfig);
32
+ try {
33
+ responseData = response.data;
34
+ } catch (e) {
35
+ responseData = {};
36
+ }
37
+ if(response.status != 200) {
38
+ logger.warn(`Warn: Get Initial Details Request failed with status code ${response.status}`);
39
+ utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
24
40
  resolve({});
25
41
  } else {
26
- try {
27
- responseData = JSON.parse(data);
28
- } catch (e) {
29
- responseData = {};
30
- }
31
- if(resp.statusCode != 200) {
32
- logger.warn(`Warn: Get Initial Details Request failed with status code ${resp.statusCode}`);
33
- utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
34
- resolve({});
35
- } else {
36
- if (!utils.isUndefined(responseData.grr) && responseData.grr.enabled && !utils.isUndefined(responseData.grr.urls)) {
37
- config.uploadUrl = responseData.grr.urls.upload_url;
38
- }
39
- resolve(responseData);
42
+ if (!utils.isUndefined(responseData.grr) && responseData.grr.enabled && !utils.isUndefined(responseData.grr.urls)) {
43
+ config.uploadUrl = responseData.grr.urls.upload_url;
40
44
  }
45
+ resolve(responseData);
46
+ }
47
+ } catch (error) {
48
+ if(error.response && error.response.status !== 200) {
49
+ logger.warn(`Warn: Get Initial Details Request failed with status code ${error.response.status}`);
50
+ utils.sendUsageReport(bsConfig, args, error.response.data["error"], Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
41
51
  }
42
- });
52
+ resolve({});
53
+ }
43
54
  });
44
55
  };
@@ -6,7 +6,6 @@ const fs = require('fs');
6
6
  const path = require('path');
7
7
  const http = require('http');
8
8
  const https = require('https');
9
- const request = require('request');
10
9
  const gitLastCommit = require('git-last-commit');
11
10
  const { v4: uuidv4 } = require('uuid');
12
11
  const os = require('os');
@@ -17,8 +16,9 @@ const { spawn, execSync } = require('child_process');
17
16
  const glob = require('glob');
18
17
  const pGitconfig = promisify(gitconfig);
19
18
  const { readCypressConfigFile } = require('./readCypressConfigUtil');
20
- const CrashReporter = require('../testObservability/crashReporter');
21
19
  const { MAX_GIT_META_DATA_SIZE_IN_BYTES, GIT_META_DATA_TRUNCATED } = require('./constants')
20
+ const CrashReporter = require('../testObservability/crashReporter');
21
+ const HttpsProxyAgent = require('https-proxy-agent');
22
22
 
23
23
  exports.debug = (text, shouldReport = false, throwable = null) => {
24
24
  if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
@@ -442,6 +442,14 @@ exports.truncateString = (field, truncateSizeInBytes) => {
442
442
  return field;
443
443
  };
444
444
 
445
+ exports.setAxiosProxy = (axiosConfig) => {
446
+ if (process.env.HTTP_PROXY || process.env.HTTPS_PROXY) {
447
+ const httpProxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY
448
+ axiosConfig.proxy = false;
449
+ axiosConfig.httpsAgent = new HttpsProxyAgent(httpProxy);
450
+ };
451
+ };
452
+
445
453
  exports.combineMacWinNpmDependencies = (runSettings) => {
446
454
  return Object.assign({}, runSettings.npm_dependencies, runSettings.win_npm_dependencies || {}, runSettings.mac_npm_dependencies || {})
447
455
  };
@@ -1,6 +1,7 @@
1
+ const axios = require('axios').default;
2
+
1
3
  const fs = require('fs'),
2
4
  path = require('path'),
3
- request = require('request'),
4
5
  logger = require('./logger').winstonLogger,
5
6
  utils = require("./utils"),
6
7
  Constants = require('./constants'),
@@ -8,7 +9,9 @@ const fs = require('fs'),
8
9
  decompress = require('decompress');
9
10
  const { isTurboScaleSession } = require('../helpers/atsHelper');
10
11
 
11
- let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
12
+ const { setAxiosProxy } = require('./helper');
13
+
14
+ let reportGenerator = async (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
12
15
  let options = {
13
16
  url: `${config.buildUrl}${buildId}/custom_report`,
14
17
  auth: {
@@ -26,32 +29,29 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
26
29
 
27
30
  logger.debug('Started fetching the build json and html reports.');
28
31
 
29
- return request.get(options, async function (err, resp, body) {
30
- let message = null;
31
- let messageType = null;
32
- let errorCode = null;
33
- let build;
34
-
35
- if (err) {
36
- message = err;
37
- messageType = Constants.messageTypes.ERROR;
38
- errorCode = 'api_failed_build_report';
32
+ let message = null;
33
+ let messageType = null;
34
+ let errorCode = null;
35
+ let build;
39
36
 
40
- logger.error('Generating the build report failed.');
41
- logger.error(utils.formatRequest(err, resp, body));
37
+ const axiosConfig = {
38
+ auth: {
39
+ username: options.auth.user,
40
+ password: options.auth.password
41
+ },
42
+ headers: options.headers
43
+ }
44
+ setAxiosProxy(axiosConfig);
42
45
 
43
- utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
44
- return;
45
- } else {
46
- logger.debug('Received reports data from upstream.');
47
- try {
48
- build = JSON.parse(body);
49
- } catch (error) {
50
- build = null;
51
- }
46
+ try {
47
+ const response = await axios.get(options.url, axiosConfig);
48
+ logger.debug('Received reports data from upstream.');
49
+ try {
50
+ build = response.data;
51
+ } catch (error) {
52
+ build = null;
52
53
  }
53
-
54
- if (resp.statusCode == 299) {
54
+ if (response.status == 299) {
55
55
  messageType = Constants.messageTypes.INFO;
56
56
  errorCode = 'api_deprecated';
57
57
  if (build) {
@@ -61,18 +61,18 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
61
61
  message = Constants.userMessages.API_DEPRECATED;
62
62
  logger.info(message);
63
63
  }
64
- } else if (resp.statusCode === 422) {
64
+ } else if (response.status === 422) {
65
65
  messageType = Constants.messageTypes.ERROR;
66
66
  errorCode = 'api_failed_build_generate_report';
67
67
  try {
68
- response = JSON.parse(body);
68
+ response = error.response.data;
69
69
  message = response.message;
70
70
  } catch (error) {
71
71
  logger.error(`Error generating the report: ${error}`);
72
72
  response = {message: message};
73
73
  }
74
- logger.error(utils.formatRequest(err, resp, body));
75
- } else if (resp.statusCode != 200) {
74
+ logger.error(utils.formatRequest(response.statusText, response, response.data));
75
+ } else if (response.status != 200) {
76
76
  messageType = Constants.messageTypes.ERROR;
77
77
  errorCode = 'api_failed_build_generate_report';
78
78
 
@@ -84,7 +84,7 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
84
84
  if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
85
85
  } else {
86
86
  message = Constants.userMessages.BUILD_GENERATE_REPORT_FAILED.replace('<build-id>', buildId);
87
- logger.error(utils.formatRequest(err, resp, body));
87
+ logger.error(utils.formatRequest(error.response.statusText, error.response, error.response.data));
88
88
  }
89
89
  } else {
90
90
  messageType = Constants.messageTypes.SUCCESS;
@@ -97,7 +97,16 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
97
97
  if (cb){
98
98
  cb();
99
99
  }
100
- });
100
+ } catch (error) {
101
+ message = error.response.statusText;
102
+ messageType = Constants.messageTypes.ERROR;
103
+ errorCode = 'api_failed_build_report';
104
+
105
+ logger.error('Generating the build report failed.');
106
+ logger.error(utils.formatRequest(error.response.statusText, error.response, error.response.data));
107
+ utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
108
+ return;
109
+ }
101
110
  }
102
111
 
103
112
  async function generateCypressBuildReport(report_data) {
@@ -116,15 +125,16 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
116
125
  const writer = fs.createWriteStream(tmpFilePath);
117
126
  logger.debug(`Fetching build reports zip.`)
118
127
  return new Promise(async (resolve, reject) => {
119
- request.get(reportJsonUrl).on('response', function(response) {
120
-
121
- if(response.statusCode != 200) {
122
- let message = `Received non 200 response while fetching reports, code: ${response.statusCode}`;
123
- reject(message);
124
- } else {
128
+ try {
129
+ const axiosConfig = {
130
+ responseType: 'stream',
131
+ };
132
+ setAxiosProxy(axiosConfig);
133
+ const response = await axios.get(reportJsonUrl, axiosConfig);
134
+ if(response.status === 200) {
125
135
  //ensure that the user can call `then()` only when the file has
126
136
  //been downloaded entirely.
127
- response.pipe(writer);
137
+ response.data.pipe(writer);
128
138
  let error = null;
129
139
  writer.on('error', err => {
130
140
  error = err;
@@ -149,7 +159,10 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
149
159
  //'error' stream;
150
160
  });
151
161
  }
152
- });
162
+ } catch (error) {
163
+ let message = `Received non 200 response while fetching reports, code: ${error.response.status}`;
164
+ reject(message);
165
+ }
153
166
  });
154
167
  }
155
168