Skip to content

Commit

Permalink
#1778 :: fix; (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
migbash authored Oct 18, 2023
1 parent c6bfa6a commit 3f71aa9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/lib/api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// #region ➤ 📦 Package Imports

import { dlogv2 } from '$lib/utils/debug.js';
import { tryCatch } from '$lib/utils/platform-functions.js';
import LZString from 'lz-string';

// #endregion ➤ 📦 Package Imports

/**
* @author
* @migbash
* @summary
* 🔹 HELPER | IMPORTANT
* @description
Expand Down Expand Up @@ -41,7 +44,7 @@ export async function get
}
);

const resJson: any = await res.json();
let resJson: any = await res.json();

if (!res?.ok)
throw new Error
Expand All @@ -50,6 +53,12 @@ export async function get
);
;

// ### NOTE: | IMPORTANT
// ### step necessary to 'decompress' lz-string encoded payload.
if (decompress)
resJson = tryCatch(() => JSON.parse(LZString.decompress(resJson?.data)));
;

// ### [🐞]
const t1: number = performance.now();
if (showTime)
Expand All @@ -59,18 +68,13 @@ export async function get
`🏹 FETCH (GET) ${endpoint}`,
[
`⏱️ ${((t1 - t0) / 1000).toFixed(2)} sec`,
`📝 Loaded via :: ${resJson?.loadType}`
`📝 Loaded via :: ${resJson?.loadType}`,
resJson
],
true
)
};

// ### NOTE: | IMPORTANT
// ### step necessary to 'decompress' lz-string encoded payload.
if (decompress)
return JSON.parse(LZString.decompress(resJson?.data));
;

return resJson;
}
catch (e)
Expand All @@ -81,6 +85,8 @@ export async function get
}

/**
* @author
* @migbash
* @summary
* 🔹 HELPER | IMPORTANT
* @description
Expand Down

0 comments on commit 3f71aa9

Please sign in to comment.