@@ -16,6 +16,7 @@ import * as http from "http";
1616import { ObjectTypeDescriptor } from "../Types" ;
1717import { ReadableWebToNodeStream } from "../Utility/ReadableWebToNodeStream" ;
1818import { LengthUnawareFormData } from "../Utility/LengthUnawareFormData" ;
19+ import { Stream } from "readable-stream" ;
1920
2021const log = getLogger ( { module : "RavenCommand" } ) ;
2122
@@ -141,7 +142,11 @@ export abstract class RavenCommand<TResult> {
141142 const fetchFn = fetcher ?? fetch ; // support for custom fetcher
142143 const response = await fetchFn ( uri , optionsToUse ) ;
143144
144- const effectiveStream : stream . Readable = fetcher ? new ReadableWebToNodeStream ( response . body ) : response . body ;
145+ const effectiveStream : stream . Readable =
146+ fetcher && response . body
147+ ? new ReadableWebToNodeStream ( response . body )
148+ : ( response . body ?? new Stream ( ) ) ;
149+
145150 effectiveStream
146151 . pipe ( passthrough ) ;
147152
@@ -226,9 +231,9 @@ export abstract class RavenCommand<TResult> {
226231 `Error processing command ${ this . constructor . name } response: ${ err . stack } ` , err ) ;
227232 } finally {
228233 closeHttpResponse ( response ) ;
229- // response.destroy();
234+ // response.destroy();
230235 // since we're calling same hosts and port a lot, we might not want to destroy sockets explicitly
231- // they're going to get back to Agent's pool and reused
236+ // they're going to get back to Agent's pool and reused
232237 }
233238
234239 return "Automatic" ;
@@ -254,9 +259,9 @@ export abstract class RavenCommand<TResult> {
254259 }
255260
256261 protected _reviveResultTypes < TResponse extends object > (
257- raw : object ,
258- conventions : DocumentConventions ,
259- typeInfo ?: TypeInfo ,
262+ raw : object ,
263+ conventions : DocumentConventions ,
264+ typeInfo ?: TypeInfo ,
260265 knownTypes ?: Map < string , ObjectTypeDescriptor > ) {
261266 return conventions . objectMapper . fromObjectLiteral < TResponse > ( raw , typeInfo , knownTypes ) ;
262267 }
0 commit comments