@@ -295,70 +295,47 @@ class AwsClient {
295295 const abortController = new AbortController ( ) ;
296296 this . _client . send ( command , { abortSignal : abortController . signal } )
297297 . then ( data => {
298- // const rawBody = data.Body;
299- // const stream = this._normalizeSdkStream(rawBody);
300- // if (!stream || typeof stream.on !== 'function') {
301- // const bodyType = rawBody?.constructor?.name || typeof rawBody;
302- // log.error('unsupported body type from AWS SDK getObject response', {
303- // method: 'AwsClient.get',
304- // backendType: this.clientType,
305- // dataStoreName: this._dataStoreName,
306- // bodyType,
307- // });
308- // return cbOnce(errorInstances.InternalError
309- // .customizeDescription('Unsupported response body type returned from AWS SDK'));
310- // }
311-
312- // if (data.$metadata?.httpHeaders) {
313- // log.trace(`${this.type} GET request response headers`, {
314- // responseHeaders: data.$metadata.httpHeaders,
315- // backendType: this.clientType,
316- // });
317- // }
318-
319- // let finished = false;
320- // const originalDestroy = stream.destroy.bind(stream);
321-
322- // const abortRequest = err => {
323- // if (finished) {
324- // return stream;
325- // }
326- // finished = true;
327- // log.debug('aborting GET request in progress', { objectGetInfo });
328- // abortController.abort(err);
329- // if (rawBody && rawBody !== stream) {
330- // rawBody.destroy?.(err);
331- // }
332- // try {
333- // originalDestroy(err);
334- // } catch (destroyErr) {
335- // log.debug('error while destroying aws sdk stream', {
336- // method: 'AwsClient.get',
337- // backendType: this.clientType,
338- // dataStoreName: this._dataStoreName,
339- // error: destroyErr,
340- // });
341- // }
342- // return stream;
343- // };
344-
345- // stream.abort = abortRequest;
346- // stream.destroy = err => abortRequest(err);
347- // stream.createReadStream = () => stream;
348-
349- // stream.on('error', err => {
350- // const logLevel = err?.code === 'NotFound' ? 'info' : 'error';
351- // logHelper(
352- // log,
353- // logLevel,
354- // `error streaming data from ${this.type}`,
355- // err,
356- // this._dataStoreName,
357- // this.clientType
358- // );
359- // });
360-
361- return process . nextTick ( ( ) => cbOnce ( null , null ) ) ;
298+ const stream = data . Body ;
299+ if ( ! stream ) {
300+ const bodyType = stream ?. constructor ?. name || typeof stream ;
301+ log . error ( 'unsupported body type from AWS SDK getObject response' , {
302+ method : 'AwsClient.get' ,
303+ backendType : this . clientType ,
304+ dataStoreName : this . _dataStoreName ,
305+ bodyType,
306+ } ) ;
307+ return cbOnce ( errorInstances . InternalError
308+ . customizeDescription ( 'Unsupported response body type returned from AWS SDK' ) ) ;
309+ }
310+
311+ if ( data . $metadata ?. httpHeaders ) {
312+ log . trace ( `${ this . type } GET request response headers` , {
313+ responseHeaders : data . $metadata . httpHeaders ,
314+ backendType : this . clientType ,
315+ } ) ;
316+ }
317+
318+ // Override destroy to also abort the HTTP request
319+ const originalDestroy = stream . destroy . bind ( stream ) ;
320+ stream . destroy = err => {
321+ log . debug ( 'aborting GET request in progress' , { objectGetInfo } ) ;
322+ abortController . abort ( err ) ;
323+ return originalDestroy ( err ) ;
324+ } ;
325+
326+ stream . on ( 'error' , err => {
327+ const logLevel = err ?. code === 'NotFound' ? 'info' : 'error' ;
328+ logHelper (
329+ log ,
330+ logLevel ,
331+ `error streaming data from ${ this . type } ` ,
332+ err ,
333+ this . _dataStoreName ,
334+ this . clientType
335+ ) ;
336+ } ) ;
337+
338+ return process . nextTick ( ( ) => cbOnce ( null , stream ) ) ;
362339 } )
363340 . catch ( err => {
364341 if ( err instanceof NoSuchKey || err instanceof NotFound ) {
0 commit comments