File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -76,11 +76,27 @@ export class DbtIntegrationClient {
76
76
if ( ! response . ok ) {
77
77
throw new Error ( `Failed to download file: ${ response . statusText } ` ) ;
78
78
}
79
+
80
+ if ( ! response . body ) {
81
+ throw new Error ( `Failed to download file: response body is null` ) ;
82
+ }
83
+
79
84
const fileStream = createWriteStream ( destinationPath ) ;
80
85
await new Promise ( ( resolve , reject ) => {
81
- response . body ?. pipe ( fileStream ) ;
82
- response . body ?. on ( "error" , reject ) ;
86
+ // Listen for errors on both streams
87
+ response . body ! . on ( "error" , ( error ) => {
88
+ fileStream . destroy ( ) ;
89
+ reject ( new Error ( `Response stream error: ${ error . message } ` ) ) ;
90
+ } ) ;
91
+
92
+ fileStream . on ( "error" , ( error ) => {
93
+ reject ( new Error ( `File stream error: ${ error . message } ` ) ) ;
94
+ } ) ;
95
+
83
96
fileStream . on ( "finish" , resolve ) ;
97
+
98
+ // Start piping after all event listeners are set up
99
+ response . body ! . pipe ( fileStream ) ;
84
100
} ) ;
85
101
86
102
this . dbtTerminal . debug ( "File downloaded successfully!" , fileName ) ;
You can’t perform that action at this time.
0 commit comments