@@ -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 }
0 commit comments