Skip to content

Commit 59679ad

Browse files
committed
Merge branch 'axios-master-without-speedboats' of github.com:browserstack/browserstack-cypress-cli into ats_fixes
2 parents 7747267 + 31f44db commit 59679ad

File tree

4 files changed

+26
-40
lines changed

4 files changed

+26
-40
lines changed

bin/helpers/buildArtifacts.js

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
110110
logger.debug(`Downloading build artifact for: ${filePath}`)
111111
return new Promise(async (resolve, reject) => {
112112
try {
113-
const response = await axios.get(url, {responseType: 'stream'});
113+
const response = await axios.get(url, {
114+
responseType: 'stream',
115+
validateStatus: status => (status >= 200 && status < 300) || status === 404
116+
});
114117
if(response.status != 200) {
115118
if (response.status === 404) {
116119
reject(Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND);
@@ -140,7 +143,7 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
140143
});
141144
}
142145
} catch (error) {
143-
reject();
146+
reject(error);
144147
}
145148
});
146149
}
@@ -261,45 +264,29 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
261264
try {
262265
response = await axios.get(options.url, options.config);
263266
buildDetails = response.data;
264-
if(response.status != 200) {
265-
logger.error('Downloading the build artifacts failed.');
266-
logger.error(`Error: Request failed with status code ${response.status}`)
267-
logger.error(utils.formatRequest(response.statusText, response, response.data));
268-
utils.sendUsageReport(bsConfig, args, JSON.stringify(buildDetails), Constants.messageTypes.ERROR, 'api_failed_build_artifacts', buildReportData, rawArgs);
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);
269273
process.exitCode = Constants.ERROR_EXIT_CODE;
270274
} else {
271-
await createDirectories(buildId, buildDetails);
272-
await parseAndDownloadArtifacts(buildId, buildDetails);
273-
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
274-
messageType = Constants.messageTypes.ERROR;
275-
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
276-
logger.error(message);
277-
process.exitCode = Constants.ERROR_EXIT_CODE;
278-
} else {
279-
messageType = Constants.messageTypes.SUCCESS;
280-
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
281-
logger.info(message);
282-
}
283-
await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs, buildReportData)
284-
utils.sendUsageReport(bsConfig, args, message, messageType, null, buildReportData, rawArgs);
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);
285278
}
279+
await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs, buildReportData)
280+
utils.sendUsageReport(bsConfig, args, message, messageType, null, buildReportData, rawArgs);
286281
} catch (err) {
282+
messageType = Constants.messageTypes.ERROR;
283+
errorCode = 'api_failed_build_artifacts';
287284
if(err.response && err.response.status !== 200) {
288-
messageType = Constants.messageTypes.ERROR;
289-
errorCode = 'api_failed_build_artifacts';
290-
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
291-
messageType = Constants.messageTypes.ERROR;
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.');
296-
}
297-
utils.sendUsageReport(bsConfig, args, err.response.data, messageType, errorCode, buildReportData, rawArgs);
298-
logger.error(`Error: Request failed with status code ${err.status}`)
299-
logger.error(utils.formatRequest(err.status, err.response, err.response.data));
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);
300289
} else {
301-
messageType = Constants.messageTypes.ERROR;
302-
errorCode = 'api_failed_build_artifacts';
303290
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
304291
messageType = Constants.messageTypes.ERROR;
305292
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
@@ -308,8 +295,8 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
308295
logger.error('Downloading the build artifacts failed.');
309296
}
310297
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, buildReportData, rawArgs);
311-
logger.error(`Error: Request failed with status code ${response.status}`)
312-
logger.error(utils.formatRequest(err, response, response.data));
298+
logger.error(`Error: Request failed with status code ${resp.status}`)
299+
logger.error(utils.formatRequest(err, resp, body));
313300
}
314301
process.exitCode = Constants.ERROR_EXIT_CODE;
315302
}

bin/helpers/downloadBuildStacktrace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const downloadBuildStacktrace = async (url) => {
1111
process.stdout.on('error', (err) => {
1212
error = err;
1313
process.stdout.close();
14-
reject(response.data.status);
14+
reject(response.status);
1515
});
1616
process.stdout.on('close', async () => {
1717
if (!error) {

bin/helpers/zipUpload.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const purgeUploadBar = (obj) => {
1717
speed: ((obj.size / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
1818
});
1919
obj.bar1.stop();
20-
// clearInterval(obj.zipInterval);
2120
}
2221

2322
const uploadSuits = (bsConfig, filePath, opts, obj) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dependencies": {
1515
"archiver": "5.3.0",
1616
"async": "3.2.3",
17-
"axios": "^1.4.0",
17+
"axios": "^1.7.7",
1818
"axios-retry": "^3.5.0",
1919
"browserstack-local": "1.5.4",
2020
"chalk": "4.1.2",

0 commit comments

Comments
 (0)