@@ -110,12 +110,15 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
110
110
logger . debug ( `Downloading build artifact for: ${ filePath } ` )
111
111
return new Promise ( async ( resolve , reject ) => {
112
112
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
+ } ) ;
114
117
if ( response . status != 200 ) {
115
- if ( response . statusCode === 404 ) {
118
+ if ( response . status === 404 ) {
116
119
reject ( Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND ) ;
117
120
}
118
- const errorMsg = `Non 200 status code, got status code: ${ response . statusCode } ` ;
121
+ const errorMsg = `Non 200 status code, got status code: ${ response . status } ` ;
119
122
reject ( errorMsg ) ;
120
123
} else {
121
124
//ensure that the user can call `then()` only when the file has
@@ -140,7 +143,7 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
140
143
} ) ;
141
144
}
142
145
} catch ( error ) {
143
- reject ( ) ;
146
+ reject ( error ) ;
144
147
}
145
148
} ) ;
146
149
}
@@ -259,45 +262,29 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
259
262
try {
260
263
response = await axios . get ( options . url , options . config ) ;
261
264
buildDetails = response . data ;
262
- if ( response . status != 200 ) {
263
- logger . error ( 'Downloading the build artifacts failed.' ) ;
264
- logger . error ( `Error: Request failed with status code ${ response . status } ` )
265
- logger . error ( utils . formatRequest ( response . statusText , response , response . data ) ) ;
266
- utils . sendUsageReport ( bsConfig , args , JSON . stringify ( buildDetails ) , Constants . messageTypes . ERROR , 'api_failed_build_artifacts' , buildReportData , rawArgs ) ;
265
+ await createDirectories ( buildId , buildDetails ) ;
266
+ await parseAndDownloadArtifacts ( buildId , buildDetails , bsConfig , args , rawArgs , buildReportData ) ;
267
+ if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
268
+ messageType = Constants . messageTypes . ERROR ;
269
+ message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , BUILD_ARTIFACTS_FAIL_COUNT ) ;
270
+ logger . error ( message ) ;
267
271
process . exitCode = Constants . ERROR_EXIT_CODE ;
268
272
} else {
269
- await createDirectories ( buildId , buildDetails ) ;
270
- await parseAndDownloadArtifacts ( buildId , buildDetails ) ;
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
- process . exitCode = Constants . ERROR_EXIT_CODE ;
276
- } else {
277
- messageType = Constants . messageTypes . SUCCESS ;
278
- message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_SUCCESS . replace ( '<build-id>' , buildId ) . replace ( '<user-path>' , process . cwd ( ) ) ;
279
- logger . info ( message ) ;
280
- }
281
- await sendUpdatesToBstack ( bsConfig , buildId , args , options , rawArgs , buildReportData )
282
- utils . sendUsageReport ( bsConfig , args , message , messageType , null , buildReportData , rawArgs ) ;
273
+ messageType = Constants . messageTypes . SUCCESS ;
274
+ message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_SUCCESS . replace ( '<build-id>' , buildId ) . replace ( '<user-path>' , process . cwd ( ) ) ;
275
+ logger . info ( message ) ;
283
276
}
277
+ await sendUpdatesToBstack ( bsConfig , buildId , args , options , rawArgs , buildReportData )
278
+ utils . sendUsageReport ( bsConfig , args , message , messageType , null , buildReportData , rawArgs ) ;
284
279
} catch ( err ) {
280
+ messageType = Constants . messageTypes . ERROR ;
281
+ errorCode = 'api_failed_build_artifacts' ;
285
282
if ( err . response && err . response . status !== 200 ) {
286
- messageType = Constants . messageTypes . ERROR ;
287
- errorCode = 'api_failed_build_artifacts' ;
288
- if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
289
- messageType = Constants . messageTypes . ERROR ;
290
- message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , BUILD_ARTIFACTS_FAIL_COUNT ) ;
291
- logger . error ( message ) ;
292
- } else {
293
- logger . error ( 'Downloading the build artifacts failed.' ) ;
294
- }
295
- utils . sendUsageReport ( bsConfig , args , err . response . data , messageType , errorCode , buildReportData , rawArgs ) ;
296
- logger . error ( `Error: Request failed with status code ${ err . status } ` )
297
- logger . error ( utils . formatRequest ( err . status , err . response , err . response . data ) ) ;
283
+ logger . error ( 'Downloading the build artifacts failed.' ) ;
284
+ logger . error ( `Error: Request failed with status code ${ err . response . status } ` )
285
+ logger . error ( utils . formatRequest ( err . response . statusText , err . response , err . response . data ) ) ;
286
+ utils . sendUsageReport ( bsConfig , args , JSON . stringify ( buildDetails ) , Constants . messageTypes . ERROR , 'api_failed_build_artifacts' , buildReportData , rawArgs ) ;
298
287
} else {
299
- messageType = Constants . messageTypes . ERROR ;
300
- errorCode = 'api_failed_build_artifacts' ;
301
288
if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
302
289
messageType = Constants . messageTypes . ERROR ;
303
290
message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , BUILD_ARTIFACTS_FAIL_COUNT ) ;
@@ -306,8 +293,8 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
306
293
logger . error ( 'Downloading the build artifacts failed.' ) ;
307
294
}
308
295
utils . sendUsageReport ( bsConfig , args , err , messageType , errorCode , buildReportData , rawArgs ) ;
309
- logger . error ( `Error: Request failed with status code ${ response . status } ` )
310
- logger . error ( utils . formatRequest ( err , response , response . data ) ) ;
296
+ logger . error ( `Error: Request failed with status code ${ resp . status } ` )
297
+ logger . error ( utils . formatRequest ( err , resp , body ) ) ;
311
298
}
312
299
process . exitCode = Constants . ERROR_EXIT_CODE ;
313
300
}
0 commit comments