@@ -56,22 +56,27 @@ function retrieveData({ debug: requestDebug, endpoint, configuration, auth, isTo
5656 } ) ;
5757 }
5858 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 } ❌ ` ) ;
6060 }
6161 } ) ;
6262}
6363exports . retrieveData = retrieveData ;
6464/* 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 } ) {
6666 return __awaiter ( this , void 0 , void 0 , function * ( ) {
6767 ( 0 , core_1 . info ) ( 'Saving the data... 📁' ) ;
6868 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+ }
7580 } ) ;
7681}
7782exports . generateExport = generateExport ;
0 commit comments