From b3c383fd0cdf891a1545599d5ac9b346badec9fa Mon Sep 17 00:00:00 2001 From: Vitaly Gashkov Date: Sun, 11 Aug 2024 12:19:40 +0500 Subject: [PATCH] fix: handle error when empty store --- package-lock.json | 4 ++-- src/core/lib/store.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 860a8f6..bc628ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "streamyx", - "version": "4.0.0-beta.55", + "version": "4.0.0-beta.56", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "streamyx", - "version": "4.0.0-beta.55", + "version": "4.0.0-beta.56", "dependencies": { "@streamyx/boosty": "file:packages/boosty", "@streamyx/core": "file:src/core", diff --git a/src/core/lib/store.ts b/src/core/lib/store.ts index 883b8ae..f7cbd92 100644 --- a/src/core/lib/store.ts +++ b/src/core/lib/store.ts @@ -15,11 +15,11 @@ export const createStore = (name: string) => { const storePath = createStorePath(name); const state = {} as Record; const getState = async (cookiesKey: string | null = 'cookies') => { - const data = await fs.readJson(storePath).catch(() => null); - if (data) Object.assign(state, data); + const data = (await fs.readJson(storePath).catch(() => {})) || {}; + Object.assign(state, data); const cookies = await getCookiesFromTxt(storePath); const hasCookiesInTxt = !!cookies.length; - const hasCookiesInState = cookiesKey && data?.[cookiesKey]; + const hasCookiesInState = cookiesKey && data[cookiesKey]; if (hasCookiesInTxt) http.setCookies(cookies); else if (hasCookiesInState) http.setCookies(data[cookiesKey]); return data as T;