Skip to content

Commit 612f771

Browse files
committed
fail if using local eval without a server-side key
1 parent bc823c4 commit 612f771

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

sdk/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ export class Flagsmith {
142142

143143
if (this.enableLocalEvaluation) {
144144
if (!this.environmentKey.startsWith('ser.')) {
145-
console.error(
146-
'In order to use local evaluation, please generate a server key in the environment settings page.'
147-
);
145+
throw new Error('Using local evaluation requires a server-side environment key');
148146
}
149147
if (this.environmentRefreshIntervalSeconds > 0){
150148
this.environmentDataPollingManager = new EnvironmentDataPollingManager(

tests/sdk/flagsmith-cache.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ test('test_get_environment_flags_uses_local_environment_when_available', async (
6161
const cache = new TestCache();
6262
const set = vi.spyOn(cache, 'set');
6363

64-
const flg = flagsmith({ cache, enableLocalEvaluation: true });
64+
const flg = flagsmith({ cache, environmentKey: 'ser.key', enableLocalEvaluation: true });
6565
const model = environmentModel(JSON.parse(environmentJSON));
6666
const getEnvironment = vi.spyOn(flg, 'getEnvironment')
6767
getEnvironment.mockResolvedValue(model)

tests/sdk/flagsmith.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ test('test_flagsmith_starts_polling_manager_on_init_if_enabled', () => {
3131

3232
test('test_flagsmith_local_evaluation_key_required', () => {
3333
fetch.mockResolvedValue(new Response(environmentJSON));
34-
console.error = vi.fn();
35-
new Flagsmith({
36-
environmentKey: 'bad.key',
37-
enableLocalEvaluation: true
38-
});
39-
expect(console.error).toBeCalled();
34+
expect(() => {
35+
new Flagsmith({
36+
environmentKey: 'bad.key',
37+
enableLocalEvaluation: true
38+
});
39+
}).toThrow('Using local evaluation requires a server-side environment key')
4040
});
4141

4242
test('test_update_environment_sets_environment', async () => {

0 commit comments

Comments
 (0)