@@ -12,7 +12,7 @@ const binaryName = 'myst';
12
12
13
13
const getFileName = function ( osPathPart , archPathPart , extension ) {
14
14
return binaryName + '_' + osPathPart + '_' + archPathPart + extension
15
- }
15
+ } ;
16
16
17
17
const getDownloadInfo = function ( version , osType , architecture ) {
18
18
osType = osType . toLowerCase ( ) ;
@@ -37,10 +37,14 @@ const getDownloadInfo = function (version, osType, architecture) {
37
37
let download = function ( url , dest , cb ) {
38
38
let file = fs . createWriteStream ( dest ) ;
39
39
https . get ( url , function ( response ) {
40
- response . pipe ( file ) ;
41
40
file . on ( 'finish' , function ( ) {
42
41
file . close ( cb ) ;
43
42
} ) ;
43
+ if ( response . statusCode >= 400 ) {
44
+ if ( cb ) cb ( new Error ( `Unsuccessful HTTP status: ${ url } ${ response . statusCode } ${ response . statusMessage } ` ) ) ;
45
+ return
46
+ }
47
+ response . pipe ( file ) ;
44
48
} ) . on ( 'error' , function ( err ) {
45
49
fs . unlink ( dest ) ;
46
50
if ( cb ) cb ( err ) ;
@@ -63,14 +67,14 @@ module.exports = function (osType, architecture, destination) {
63
67
const { url, filename} = getDownloadInfo ( version , osType , architecture ) ;
64
68
download ( url , filename , function ( err ) {
65
69
if ( err ) return console . log ( err ) ;
66
- console . log ( 'downloaded ' , url ) ;
70
+ console . log ( 'Downloaded ' , url ) ;
67
71
const format = osType . includes ( 'windows' ) ? 'zip' : 'tar.gz' ;
68
72
unpack ( filename , destination , format , function ( err ) {
69
73
if ( err ) return console . error ( err ) ;
70
- console . log ( 'unpacked to ' , destination ) ;
74
+ console . log ( 'Unpacked to ' , destination ) ;
71
75
fs . unlink ( filename , ( err ) => {
72
76
if ( err ) return console . error ( err ) ;
73
- console . log ( 'deleted ' , filename ) ;
77
+ console . log ( 'Deleted ' , filename ) ;
74
78
} )
75
79
} )
76
80
} ) ;
0 commit comments