@@ -9,7 +9,9 @@ import * as zlib from 'zlib';
9
9
import type { Envelope , EnvelopeItem } from '@sentry/types' ;
10
10
import { parseEnvelope } from '@sentry/utils' ;
11
11
12
+ const readFile = util . promisify ( fs . readFile ) ;
12
13
const writeFile = util . promisify ( fs . writeFile ) ;
14
+ const unlink = util . promisify ( fs . unlink ) ;
13
15
14
16
interface EventProxyServerOptions {
15
17
/** Port to start the event proxy server at. */
@@ -83,12 +85,9 @@ function replaceDynamicValues(data: string): string[] {
83
85
* The new content is saved into a new file with the url as the filename.
84
86
* The temporary file is deleted in the end.
85
87
*/
86
- function transformSavedJSON ( ) {
87
- fs . readFile ( TEMPORARY_FILE_PATH , 'utf8' , ( err , data ) => {
88
- if ( err ) {
89
- console . error ( 'Error reading file' , err ) ;
90
- return ;
91
- }
88
+ async function transformSavedJSON ( ) {
89
+ try {
90
+ const data = await readFile ( TEMPORARY_FILE_PATH , 'utf8' ) ;
92
91
93
92
const jsonData = addCommaAfterEachLine ( data ) ;
94
93
const transformedJSON = replaceDynamicValues ( jsonData ) ;
@@ -98,23 +97,15 @@ function transformSavedJSON() {
98
97
const url = objWithReq . request . url ;
99
98
const filepath = `payload-files/${ extractPathFromUrl ( url ) } .json` ;
100
99
101
- fs . writeFile ( filepath , JSON . stringify ( transformedJSON , null , 2 ) , err => {
102
- if ( err ) {
103
- console . error ( 'Error writing file' , err ) ;
104
- } else {
105
- console . log ( `Successfully modified timestamp in ${ filepath } ` ) ;
106
- }
107
- } ) ;
100
+ await writeFile ( filepath , JSON . stringify ( transformedJSON , null , 2 ) ) ;
101
+ console . log ( `Successfully modified timestamp in ${ filepath } ` ) ;
108
102
}
109
- } ) ;
110
103
111
- fs . unlink ( TEMPORARY_FILE_PATH , err => {
112
- if ( err ) {
113
- console . error ( 'Error deleting file' , err ) ;
114
- } else {
115
- console . log ( `Successfully deleted ${ TEMPORARY_FILE_PATH } ` ) ;
116
- }
117
- } ) ;
104
+ await unlink ( TEMPORARY_FILE_PATH ) ;
105
+ console . log ( `Successfully deleted ${ TEMPORARY_FILE_PATH } ` ) ;
106
+ } catch ( err ) {
107
+ console . error ( 'Error' , err ) ;
108
+ }
118
109
}
119
110
120
111
/**
0 commit comments