@@ -93,20 +93,20 @@ export class NodeHttpsClient implements HttpsClient {
9393 }
9494 }
9595
96- if ( body && request . onUploadProgress ) {
97- const onUploadProgress = request . onUploadProgress ;
98- const uploadReportStream = new ReportTransform ( onUploadProgress ) ;
99- if ( isReadableStream ( body ) ) {
100- body . pipe ( uploadReportStream ) ;
101- } else {
102- uploadReportStream . end ( body ) ;
103- }
104-
105- body = uploadReportStream ;
106- }
107-
10896 try {
10997 const result = await new Promise < PipelineResponse > ( ( resolve , reject ) => {
98+ if ( body && request . onUploadProgress ) {
99+ const onUploadProgress = request . onUploadProgress ;
100+ const uploadReportStream = new ReportTransform ( onUploadProgress ) ;
101+ uploadReportStream . on ( "error" , reject ) ;
102+ if ( isReadableStream ( body ) ) {
103+ body . pipe ( uploadReportStream ) ;
104+ } else {
105+ uploadReportStream . end ( body ) ;
106+ }
107+
108+ body = uploadReportStream ;
109+ }
110110 const options = this . getRequestOptions ( request ) ;
111111 const req = https . request ( options , async ( res ) => {
112112 const headers = getResponseHeaders ( res ) ;
@@ -123,6 +123,7 @@ export class NodeHttpsClient implements HttpsClient {
123123 const onDownloadProgress = request . onDownloadProgress ;
124124 if ( onDownloadProgress ) {
125125 const downloadReportStream = new ReportTransform ( onDownloadProgress ) ;
126+ downloadReportStream . on ( "error" , reject ) ;
126127 responseStream . pipe ( downloadReportStream ) ;
127128 responseStream = downloadReportStream ;
128129 }
@@ -144,14 +145,14 @@ export class NodeHttpsClient implements HttpsClient {
144145 reject ( new AbortError ( "The operation was aborted." ) ) ;
145146 }
146147 } ) ;
147- if ( body ) {
148- if ( isReadableStream ( body ) ) {
149- body . pipe ( req ) ;
150- } else {
151- req . write ( body ) ;
152- }
148+ if ( body && isReadableStream ( body ) ) {
149+ body . pipe ( req ) ;
150+ } else if ( body ) {
151+ req . end ( body ) ;
152+ } else {
153+ // streams don't like "undefined" being passed as data
154+ req . end ( ) ;
153155 }
154- req . end ( ) ;
155156 } ) ;
156157 return result ;
157158 } finally {
0 commit comments