@@ -118,10 +118,10 @@ class HttpURLConnectionClient implements ClientInterface {
118
118
connectionRequest . flushHeaders ( ) ;
119
119
120
120
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 } = {
122
122
statusCode : res . statusCode ,
123
123
headers : res . headers ,
124
- body : [ ]
124
+ body : ""
125
125
} ;
126
126
127
127
const getException = ( responseBody : string ) : HttpClientException => new HttpClientException ( {
@@ -134,23 +134,18 @@ class HttpURLConnectionClient implements ClientInterface {
134
134
135
135
let exception : HttpClientException | Error = getException ( response . body . toString ( ) ) ;
136
136
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 ;
139
139
} ) ;
140
140
141
141
res . on ( "end" , ( ) : void => {
142
142
if ( ! res . complete ) {
143
143
reject ( new Error ( "The connection was terminated while the message was still being sent" ) ) ;
144
144
}
145
145
146
- if ( response . body . length ) {
147
- response . body = ( response . body as [ ] ) . join ( ) ;
148
- }
149
-
150
146
if ( res . statusCode && ( res . statusCode < 200 || res . statusCode >= 300 ) ) {
151
147
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 ) ;
154
149
const isApiError = "status" in formattedData ;
155
150
const isRequestError = "errors" in formattedData ;
156
151
@@ -160,12 +155,12 @@ class HttpURLConnectionClient implements ClientInterface {
160
155
statusCode : formattedData . status ,
161
156
errorCode : formattedData . errorCode ,
162
157
responseHeaders : res . headers ,
163
- responseBody : dataString ,
158
+ responseBody : response . body ,
164
159
} ) ;
165
160
} else if ( isRequestError ) {
166
- exception = new Error ( dataString ) ;
161
+ exception = new Error ( response . body ) ;
167
162
} else {
168
- exception = getException ( dataString ) ;
163
+ exception = getException ( response . body ) ;
169
164
}
170
165
} catch ( e ) {
171
166
reject ( exception ) ;
0 commit comments