@@ -18,6 +18,7 @@ import {
18
18
} from "@fluentui/react-components" ;
19
19
import { getCellAddress } from "../taskpane" ;
20
20
import { useState } from "react" ;
21
+ import pako from 'pako' ;
21
22
22
23
23
24
// ProJets brand color
@@ -175,7 +176,7 @@ const App = () => {
175
176
176
177
const readWorkbook = async ( ) => {
177
178
resetProgress ( ) ;
178
-
179
+
179
180
const readRange = async ( worksheetData , range ) => {
180
181
range . load ( [
181
182
"columnCount" ,
@@ -317,17 +318,42 @@ const App = () => {
317
318
318
319
try {
319
320
const workbook = await readWorkbook ( ) ;
320
-
321
- await fetch ( targetUrl as string , {
322
- method : "POST" ,
323
- body : JSON . stringify ( {
321
+ let jsonData = JSON . stringify ( {
324
322
worksheets : workbook ,
325
323
params : { param1, param2 } ,
326
- } ) ,
324
+ } ) ;
325
+
326
+ const compressedData = pako . gzip ( jsonData ) ;
327
+ const response = await fetch ( targetUrl as string , {
328
+ method : 'POST' ,
329
+ headers : {
330
+ 'Content-Type' : 'application/json' ,
331
+ 'Content-Encoding' : 'gzip' ,
332
+ 'Accept-Encoding' : 'gzip'
333
+ } ,
334
+ body : compressedData
327
335
} ) ;
336
+
337
+ if ( ! response . ok ) {
338
+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
339
+ }
340
+
341
+ // // Handle compressed response
342
+ // const responseBuffer = await response.arrayBuffer();
343
+ // const responseUint8Array = new Uint8Array(responseBuffer);
344
+ // const responseString = responseUint8Array.toString();
345
+ // // const decompressedResponse = pako.ungzip(responseUint8Array, { to: 'string' });
346
+
347
+ // return JSON.parse(responseString);
348
+ return await response . json ( ) ;
328
349
} catch ( error ) {
329
- setReadErrorMessage ( error . message || "An error occurred during the read operation" ) ;
330
- } finally {
350
+ // Compose a detailed error message with stack trace
351
+ const detailedError =
352
+ ( error . message ? `Error: ${ error . message } \n` : "" ) +
353
+ ( error . stack ? `Stack trace:\n${ error . stack } ` : "" ) ;
354
+ console . error ( "Error reading workbook:" , detailedError ) ;
355
+ setReadErrorMessage ( detailedError || "An error occurred during the read operation" ) ;
356
+ } finally {
331
357
setIsReadLoading ( false ) ;
332
358
}
333
359
} ;
@@ -411,8 +437,13 @@ const App = () => {
411
437
const jsonData = JSON . parse ( textArea as string ) ;
412
438
await writeWorkbook ( jsonData ) ;
413
439
} catch ( error ) {
414
- setWriteErrorMessage ( error . message || "An error occurred during the write operation" ) ;
415
- } finally {
440
+ // Compose a detailed error message with stack trace
441
+ const detailedError =
442
+ ( error . message ? `Error: ${ error . message } \n` : "" ) +
443
+ ( error . stack ? `Stack trace:\n${ error . stack } ` : "" ) ;
444
+ console . error ( "Error reading workbook:" , detailedError ) ;
445
+ setReadErrorMessage ( detailedError || "An error occurred during the write operation" ) ;
446
+ } finally {
416
447
setIsWriteLoading ( false ) ;
417
448
}
418
449
} ;
0 commit comments