@@ -272,14 +272,14 @@ export class ScrapflyClient {
272272 throw new Error ( 'Screenshot binary does not exist' ) ;
273273 }
274274
275- const format = result . metadata . format ;
275+ const extension_name = result . metadata . extension_name ;
276276 let file_path ;
277277
278278 if ( savePath ) {
279279 fs . mkdirSync ( savePath , { recursive : true } ) ;
280- file_path = path . join ( savePath , `${ name } .${ format } ` ) ;
280+ file_path = path . join ( savePath , `${ name } .${ extension_name } ` ) ;
281281 } else {
282- file_path = `${ name } .${ format } ` ;
282+ file_path = `${ name } .${ extension_name } ` ;
283283 }
284284
285285 const content = Buffer . from ( result . image ) ;
@@ -292,13 +292,11 @@ export class ScrapflyClient {
292292 async handleScreenshotResponse ( response : Response ) : Promise < ScreenshotResult > {
293293 if ( response . headers . get ( 'content-encoding' ) != 'gzip' ) {
294294 const data = ( await response . json ( ) ) as any ;
295- if ( response . headers . get ( 'content-encoding' ) !== 'gzip' ) {
296- if ( data . http_code == 401 || response . status == 401 ) {
297- throw new errors . BadApiKeyError ( JSON . stringify ( data ) ) ;
298- }
299- if ( 'error_id' in data ) {
300- throw new errors . ScreenshotApiError ( JSON . stringify ( data ) ) ;
301- }
295+ if ( data . http_code == 401 || response . status == 401 ) {
296+ throw new errors . BadApiKeyError ( JSON . stringify ( data ) ) ;
297+ }
298+ if ( 'error_id' in data ) {
299+ throw new errors . ScreenshotApiError ( JSON . stringify ( data ) ) ;
302300 }
303301 }
304302 if ( ! response . ok ) {
@@ -350,7 +348,7 @@ export class ScrapflyClient {
350348 }
351349 if ( ! response . ok ) {
352350 throw new errors . ApiHttpClientError ( JSON . stringify ( await response . json ( ) ) ) ;
353- }
351+ }
354352 const result = new ExtractionResult ( data ) ;
355353 return result ;
356354 }
@@ -381,7 +379,7 @@ export class ScrapflyClient {
381379 log . error ( 'error' , e ) ;
382380 throw e ;
383381 }
384- const result = await this . handleExtractionResponse ( response )
382+ const result = await this . handleExtractionResponse ( response ) ;
385383 return result ;
386384 }
387385}
0 commit comments