@@ -226,31 +226,31 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
226226 }
227227 try {
228228 const response = await axios . get ( options . url , options . config ) ;
229- try {
230- buildDetails = response . data ;
231- if ( response . status != 200 ) {
232- logger . error ( 'Downloading the build artifacts failed.' ) ;
233- logger . error ( `Error: Request failed with status code ${ response . status } ` )
234- logger . error ( utils . formatRequest ( response . statusText , response , response . data ) ) ;
235- utils . sendUsageReport ( bsConfig , args , JSON . stringify ( buildDetails ) , Constants . messageTypes . ERROR , 'api_failed_build_artifacts' , buildReportData , rawArgs ) ;
229+ buildDetails = response . data ;
230+ if ( response . status != 200 ) {
231+ logger . error ( 'Downloading the build artifacts failed.' ) ;
232+ logger . error ( `Error: Request failed with status code ${ response . status } ` )
233+ logger . error ( utils . formatRequest ( response . statusText , response , response . data ) ) ;
234+ utils . sendUsageReport ( bsConfig , args , JSON . stringify ( buildDetails ) , Constants . messageTypes . ERROR , 'api_failed_build_artifacts' , buildReportData , rawArgs ) ;
235+ process . exitCode = Constants . ERROR_EXIT_CODE ;
236+ } else {
237+ await createDirectories ( buildId , buildDetails ) ;
238+ await parseAndDownloadArtifacts ( buildId , buildDetails ) ;
239+ if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
240+ messageType = Constants . messageTypes . ERROR ;
241+ message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , BUILD_ARTIFACTS_FAIL_COUNT ) ;
242+ logger . error ( message ) ;
236243 process . exitCode = Constants . ERROR_EXIT_CODE ;
237244 } else {
238- await createDirectories ( buildId , buildDetails ) ;
239- await parseAndDownloadArtifacts ( buildId , buildDetails ) ;
240- if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
241- messageType = Constants . messageTypes . ERROR ;
242- message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , BUILD_ARTIFACTS_FAIL_COUNT ) ;
243- logger . error ( message ) ;
244- process . exitCode = Constants . ERROR_EXIT_CODE ;
245- } else {
246- messageType = Constants . messageTypes . SUCCESS ;
247- message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_SUCCESS . replace ( '<build-id>' , buildId ) . replace ( '<user-path>' , process . cwd ( ) ) ;
248- logger . info ( message ) ;
249- }
250- await sendUpdatesToBstack ( bsConfig , buildId , args , options , rawArgs , buildReportData )
251- utils . sendUsageReport ( bsConfig , args , message , messageType , null , buildReportData , rawArgs ) ;
245+ messageType = Constants . messageTypes . SUCCESS ;
246+ message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_SUCCESS . replace ( '<build-id>' , buildId ) . replace ( '<user-path>' , process . cwd ( ) ) ;
247+ logger . info ( message ) ;
252248 }
253- } catch ( err ) {
249+ await sendUpdatesToBstack ( bsConfig , buildId , args , options , rawArgs , buildReportData )
250+ utils . sendUsageReport ( bsConfig , args , message , messageType , null , buildReportData , rawArgs ) ;
251+ }
252+ } catch ( err ) {
253+ if ( err . response && err . response . status !== 200 ) {
254254 messageType = Constants . messageTypes . ERROR ;
255255 errorCode = 'api_failed_build_artifacts' ;
256256 if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
@@ -260,16 +260,14 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildR
260260 } else {
261261 logger . error ( 'Downloading the build artifacts failed.' ) ;
262262 }
263- utils . sendUsageReport ( bsConfig , args , err , messageType , errorCode , buildReportData , rawArgs ) ;
264- logger . error ( `Error: Request failed with status code ${ err . response . status } ` )
265- logger . error ( utils . formatRequest ( err . response . statusText , err . response , err . response . data ) ) ;
266- process . exitCode = Constants . ERROR_EXIT_CODE ;
263+ utils . sendUsageReport ( bsConfig , args , err . response . data , messageType , errorCode , buildReportData , rawArgs ) ;
264+ logger . error ( `Error: Request failed with status code ${ err . status } ` )
265+ logger . error ( utils . formatRequest ( err . status , err . response , err . response . data ) ) ;
266+ } else {
267+ logger . info ( err ) ;
267268 }
268- resolve ( ) ;
269- } catch ( error ) {
270- logger . error ( utils . formatRequest ( error . response . statusText , error . response , error . response . data ) ) ;
271- utils . sendUsageReport ( bsConfig , args , error . response , Constants . messageTypes . ERROR , 'api_failed_build_artifacts' , buildReportData , rawArgs ) ;
272269 process . exitCode = Constants . ERROR_EXIT_CODE ;
273270 }
271+ resolve ( ) ;
274272 } ) ;
275273} ;
0 commit comments