File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed
packages/simulator/streams Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -36,21 +36,30 @@ const downloadIfNotExists = (operator) => {
3636 reject ( err )
3737 } )
3838 )
39- . catch ( ( err ) => error ( 'Error fetching GTFS' , err ) || reject ( ) )
39+ . catch ( ( err ) => error ( 'Error fetching GTFS' , err ) || reject ( err ) )
4040 } else {
41- resolve ( )
41+ resolve ( zipFile )
4242 }
4343 } )
4444}
4545
4646const downloadAndExtractIfNotExists = ( operator ) => {
47- return downloadIfNotExists ( operator ) . then ( ( zipFile ) => {
48- const outPath = path . join ( __dirname , `../.cache/${ operator } ` )
49- const zip = new AdmZip ( zipFile )
50- if ( ! fs . existsSync ( outPath ) ) fs . mkdirSync ( outPath , true )
51- zip . extractAllTo ( outPath , true )
52- return zipFile
53- } )
47+ return downloadIfNotExists ( operator )
48+ . then ( ( zipFile ) => {
49+ try {
50+ const outPath = path . join ( __dirname , `../.cache/${ operator } ` )
51+ const zip = new AdmZip ( zipFile )
52+ if ( ! fs . existsSync ( outPath ) ) fs . mkdirSync ( outPath , true )
53+ zip . extractAllTo ( outPath , true )
54+ return zipFile
55+ } catch ( err ) {
56+ error ( 'Error unpacking' , err )
57+ fs . rmSync ( zipFile ) // try again next time
58+ }
59+ } )
60+ . catch ( ( err ) => {
61+ error ( 'Error when unpacking GTFS file' , err )
62+ } )
5463}
5564
5665function gtfs ( operator ) {
You can’t perform that action at this time.
0 commit comments