@@ -118,10 +118,10 @@ class HttpURLConnectionClient implements ClientInterface {
118118 connectionRequest . flushHeaders ( ) ;
119119
120120 connectionRequest . on ( "response" , ( res : IncomingMessage ) : void => {
121- const response : { headers : IncomingHttpHeaders ; body : ( string | Buffer ) [ ] | string ; statusCode : number | undefined } = {
121+ const response : { headers : IncomingHttpHeaders ; body : string ; statusCode : number | undefined } = {
122122 statusCode : res . statusCode ,
123123 headers : res . headers ,
124- body : [ ]
124+ body : ""
125125 } ;
126126
127127 const getException = ( responseBody : string ) : HttpClientException => new HttpClientException ( {
@@ -134,23 +134,18 @@ class HttpURLConnectionClient implements ClientInterface {
134134
135135 let exception : HttpClientException | Error = getException ( response . body . toString ( ) ) ;
136136
137- res . on ( "data" , ( data : string | Buffer ) : void => {
138- ( response . body as ( string | Buffer ) [ ] ) . push ( data ) ;
137+ res . on ( "data" , ( chunk : string ) : void => {
138+ response . body += chunk ;
139139 } ) ;
140140
141141 res . on ( "end" , ( ) : void => {
142142 if ( ! res . complete ) {
143143 reject ( new Error ( "The connection was terminated while the message was still being sent" ) ) ;
144144 }
145145
146- if ( response . body . length ) {
147- response . body = ( response . body as [ ] ) . join ( ) ;
148- }
149-
150146 if ( res . statusCode && ( res . statusCode < 200 || res . statusCode >= 300 ) ) {
151147 try {
152- const dataString = response . body . toString ( ) ;
153- const formattedData : ApiError | { [ key : string ] : never } = JSON . parse ( dataString ) ;
148+ const formattedData : ApiError | { [ key : string ] : never } = JSON . parse ( response . body ) ;
154149 const isApiError = "status" in formattedData ;
155150 const isRequestError = "errors" in formattedData ;
156151
@@ -160,12 +155,12 @@ class HttpURLConnectionClient implements ClientInterface {
160155 statusCode : formattedData . status ,
161156 errorCode : formattedData . errorCode ,
162157 responseHeaders : res . headers ,
163- responseBody : dataString ,
158+ responseBody : response . body ,
164159 } ) ;
165160 } else if ( isRequestError ) {
166- exception = new Error ( dataString ) ;
161+ exception = new Error ( response . body ) ;
167162 } else {
168- exception = getException ( dataString ) ;
163+ exception = getException ( response . body ) ;
169164 }
170165 } catch ( e ) {
171166 reject ( exception ) ;
0 commit comments