diff --git a/src/statsig/client.ts b/src/statsig/client.ts index 6bcbb05..f6c72b4 100644 --- a/src/statsig/client.ts +++ b/src/statsig/client.ts @@ -109,7 +109,7 @@ export function initStatsigClient( */ export function getStatsigClientSync(): StatsigClient { if (!client) { - throw new Error('[@lovart-open/statsig] Not initialized. Call initStatsigClient() first.'); + throw new Error('[@lovart-open/flags/statsig] Not initialized. Call initStatsigClient() first.'); } return client; } diff --git a/src/statsig/flags.ts b/src/statsig/flags.ts index b76bfbb..ed259a1 100644 --- a/src/statsig/flags.ts +++ b/src/statsig/flags.ts @@ -88,11 +88,15 @@ export class FlagStore> { } // 4. Remote value from Statsig - const currentGate = gate ?? getStatsigClientSync().getFeatureGate(keyStr, evaluationOptions); - return { - flag: currentGate.value, - source: currentGate.idType ? 'remote' : 'fallback', - }; + try { + const currentGate = gate ?? getStatsigClientSync().getFeatureGate(keyStr, evaluationOptions); + return { + flag: currentGate.value, + source: currentGate.idType ? 'remote' : 'fallback', + }; + } catch { + return { flag: false, source: 'fallback' }; + } } } diff --git a/src/statsig/params.ts b/src/statsig/params.ts index a06410e..1748ca1 100644 --- a/src/statsig/params.ts +++ b/src/statsig/params.ts @@ -245,12 +245,17 @@ export class ParamStore } // 4. Remote value from Statsig else { - const clientStore = statsigStore ?? getStatsigClientSync().getParameterStore(storeKey as string, evaluationOptions); - const config = (clientStore as any)?.__configuration?.[paramKey as string]; - if (config !== undefined) { - value = clientStore.get(paramKey as string, def.fallback); - source = 'remote'; - } else { + try { + const clientStore = statsigStore ?? getStatsigClientSync().getParameterStore(storeKey as string, evaluationOptions); + const config = (clientStore as any)?.__configuration?.[paramKey as string]; + if (config !== undefined) { + value = clientStore.get(paramKey as string, def.fallback); + source = 'remote'; + } else { + value = def.fallback; + source = 'fallback'; + } + } catch { value = def.fallback; source = 'fallback'; }