@@ -116,10 +116,10 @@ class HttpURLConnectionClient implements ClientInterface {
116116 connectionRequest . flushHeaders ( ) ;
117117
118118 connectionRequest . on ( "response" , ( res : IncomingMessage ) : void => {
119- const response : { headers : IncomingHttpHeaders ; body : ( string | Buffer ) [ ] | string ; statusCode : number | undefined } = {
119+ const response : { headers : IncomingHttpHeaders ; body : string ; statusCode : number | undefined } = {
120120 statusCode : res . statusCode ,
121121 headers : res . headers ,
122- body : [ ]
122+ body : ""
123123 } ;
124124
125125 const getException = ( responseBody : string ) : HttpClientException => new HttpClientException ( {
@@ -132,23 +132,18 @@ class HttpURLConnectionClient implements ClientInterface {
132132
133133 let exception : HttpClientException | Error = getException ( response . body . toString ( ) ) ;
134134
135- res . on ( "data" , ( data : string | Buffer ) : void => {
136- ( response . body as ( string | Buffer ) [ ] ) . push ( data ) ;
135+ res . on ( "data" , ( chunk : string ) : void => {
136+ response . body += chunk ;
137137 } ) ;
138138
139139 res . on ( "end" , ( ) : void => {
140140 if ( ! res . complete ) {
141141 reject ( new Error ( "The connection was terminated while the message was still being sent" ) ) ;
142142 }
143143
144- if ( response . body . length ) {
145- response . body = ( response . body as [ ] ) . join ( ) ;
146- }
147-
148144 if ( res . statusCode && ( res . statusCode < 200 || res . statusCode >= 300 ) ) {
149145 try {
150- const dataString = response . body . toString ( ) ;
151- const formattedData : ApiError | { [ key : string ] : never } = JSON . parse ( dataString ) ;
146+ const formattedData : ApiError | { [ key : string ] : never } = JSON . parse ( response . body ) ;
152147 const isApiError = "status" in formattedData ;
153148 const isRequestError = "errors" in formattedData ;
154149
@@ -158,12 +153,12 @@ class HttpURLConnectionClient implements ClientInterface {
158153 statusCode : formattedData . status ,
159154 errorCode : formattedData . errorCode ,
160155 responseHeaders : res . headers ,
161- responseBody : dataString ,
156+ responseBody : response . body ,
162157 } ) ;
163158 } else if ( isRequestError ) {
164- exception = new Error ( dataString ) ;
159+ exception = new Error ( response . body ) ;
165160 } else {
166- exception = getException ( dataString ) ;
161+ exception = getException ( response . body ) ;
167162 }
168163 } catch ( e ) {
169164 reject ( exception ) ;
0 commit comments