diff --git a/native/components/feature-flags-provider.react.js b/native/components/feature-flags-provider.react.js --- a/native/components/feature-flags-provider.react.js +++ b/native/components/feature-flags-provider.react.js @@ -5,6 +5,7 @@ import { Platform } from 'react-native'; import { fetchFeatureFlags } from 'lib/utils/feature-flags-utils.js'; +import sleep from 'lib/utils/sleep.js'; import { useIsCurrentUserStaff } from 'native/utils/staff-utils.js'; import { codeVersion } from '../redux/persist.js'; @@ -64,11 +65,12 @@ React.useEffect(() => { (async () => { try { - const config = await fetchFeatureFlags( - Platform.OS, - isStaff, - codeVersion, + const config = await tryMultipleTimes( + () => fetchFeatureFlags(Platform.OS, isStaff, codeVersion), + 3, + 5000, ); + const configuration = {}; for (const feature of config.enabledFeatures) { configuration[feature] = true; @@ -94,4 +96,24 @@ ); } +async function tryMultipleTimes( + f: () => Promise, + numberOfTries: number, + delay: number, +): Promise { + let lastError; + while (numberOfTries > 0) { + try { + return await f(); + } catch (e) { + --numberOfTries; + lastError = e; + if (numberOfTries > 0) { + await sleep(delay); + } + } + } + throw lastError; +} + export { FeatureFlagsContext, FeatureFlagsProvider, featureFlagsStorageKey };