Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/feature-flags-utils.js
- This file was added.
// @flow | |||||
import featureFlags from '../facts/feature-flags.js'; | |||||
type FeatureFlagsConfiguration = { | |||||
+enabledFeatures: $ReadOnlyArray<string>, | |||||
}; | |||||
async function fetchFeatureFlags( | |||||
platform: string, | |||||
isStaff: boolean, | |||||
codeVersion: number, | |||||
): Promise<FeatureFlagsConfiguration> { | |||||
const url = `${ | |||||
featureFlags.url | |||||
}/features?platform=${platform}&is_staff=${isStaff.toString()}&code_version=${codeVersion}`; | |||||
const response = await fetch(url, { | |||||
headers: { | |||||
Accept: 'application/json', | |||||
}, | |||||
}); | |||||
const text = await response.text(); | |||||
try { | |||||
const json = JSON.parse(text); | |||||
return { | |||||
enabledFeatures: json.enabled_features, | |||||
}; | |||||
} catch (e) { | |||||
console.log(text); | |||||
throw e; | |||||
} | |||||
bartek: Why not [[ https://developer.mozilla.org/en-US/docs/Web/API/Response/json | response.json() ]]? | |||||
tomekAuthorUnsubmitted Done Inline ActionsI used the same approach that we use in callServerEndpoint but agree, using .json() might be better. tomek: I used the same approach that we use in `callServerEndpoint` but agree, using `.json()` might… | |||||
} | |||||
export { fetchFeatureFlags }; |
Why not response.json()?