@@ -110,7 +110,10 @@ 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
118
if ( response . status === 404 ) {
116
119
reject ( Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_NOT_FOUND ) ;
@@ -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
}
@@ -261,45 +264,29 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
261
264
try {
262
265
response = await axios . get ( options . url , options . config ) ;
263
266
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 ) ;
269
273
process . exitCode = Constants . ERROR_EXIT_CODE ;
270
274
} 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 ) ;
285
278
}
279
+ await sendUpdatesToBstack ( bsConfig , buildId , args , options , rawArgs , buildReportData )
280
+ utils . sendUsageReport ( bsConfig , args , message , messageType , null , buildReportData , rawArgs ) ;
286
281
} catch ( err ) {
282
+ messageType = Constants . messageTypes . ERROR ;
283
+ errorCode = 'api_failed_build_artifacts' ;
287
284
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 ) ;
300
289
} else {
301
- messageType = Constants . messageTypes . ERROR ;
302
- errorCode = 'api_failed_build_artifacts' ;
303
290
if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
304
291
messageType = Constants . messageTypes . ERROR ;
305
292
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
308
295
logger . error ( 'Downloading the build artifacts failed.' ) ;
309
296
}
310
297
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 ) ) ;
313
300
}
314
301
process . exitCode = Constants . ERROR_EXIT_CODE ;
315
302
}
0 commit comments