@@ -56,22 +56,27 @@ function retrieveData({ debug: requestDebug, endpoint, configuration, auth, isTo
56
56
} ) ;
57
57
}
58
58
catch ( error ) {
59
- throw new Error ( `There was an error fetching from the API: ${ error } ` ) ;
59
+ throw new Error ( `There was an error fetching from the API: ${ error } ❌ ` ) ;
60
60
}
61
61
} ) ;
62
62
}
63
63
exports . retrieveData = retrieveData ;
64
64
/* Saves the data to the local file system and exports an environment variable containing the retrieved data. */
65
- function generateExport ( { data, format, saveLocation, saveName } ) {
65
+ function generateExport ( { data, encoding , format, saveLocation, saveName } ) {
66
66
return __awaiter ( this , void 0 , void 0 , function * ( ) {
67
67
( 0 , core_1 . info ) ( 'Saving the data... 📁' ) ;
68
68
const file = `${ saveLocation ? saveLocation : 'fetch-api-data-action' } /${ saveName ? saveName : 'data' } .${ format ? format : 'json' } ` ;
69
- yield ( 0 , io_1 . mkdirP ) ( `${ saveLocation ? saveLocation : 'fetch-api-data-action' } ` ) ;
70
- yield fs_1 . promises . writeFile ( file , data , 'utf8' ) ;
71
- ( 0 , core_1 . info ) ( `Saved ${ file } 💾` ) ;
72
- yield fs_1 . promises . writeFile ( `${ saveLocation ? saveLocation : 'fetch-api-data-action' } /${ saveName ? saveName : 'data' } .json` , data , 'utf8' ) ;
73
- ( 0 , core_1 . exportVariable ) ( 'fetch-api-data' , data ) ;
74
- return constants_1 . Status . SUCCESS ;
69
+ const dataEncoding = encoding ? encoding : 'utf8' ;
70
+ try {
71
+ yield ( 0 , io_1 . mkdirP ) ( `${ saveLocation ? saveLocation : 'fetch-api-data-action' } ` ) ;
72
+ yield fs_1 . promises . writeFile ( file , data , dataEncoding ) ;
73
+ ( 0 , core_1 . info ) ( `Saved ${ file } 💾` ) ;
74
+ ( 0 , core_1 . exportVariable ) ( 'fetch-api-data' , data ) ;
75
+ return constants_1 . Status . SUCCESS ;
76
+ }
77
+ catch ( error ) {
78
+ throw new Error ( `There was an error generating the export file: ${ error } ❌` ) ;
79
+ }
75
80
} ) ;
76
81
}
77
82
exports . generateExport = generateExport ;
0 commit comments