Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ describe('sdk-client object', () => {
expect(devTestFlag).toBe(true);
});

test('variation flag not found', async () => {
test('variation flag not found should give a warning message', async () => {
await ldc.identify({ kind: 'user', key: 'test-user' });
const errorListener = jest.fn().mockName('errorListener');
ldc.on('error', errorListener);

const p = ldc.identify(context);
ldc.variation('does-not-exist', 'not-found');
const flagValue = ldc.variation('does-not-exist', 'not-found');

await expect(p).resolves.toBeUndefined();
expect(errorListener).toHaveBeenCalledTimes(1);
const error = errorListener.mock.calls[0][1];
expect(error.message).toMatch(/unknown feature/i);

expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('Unknown feature'));
expect(flagValue).toBe('not-found');
});

test('variationDetail flag not found', async () => {
test('variationDetail flag not found should return an error detail', async () => {
await ldc.identify(context);
const flag = ldc.variationDetail('does-not-exist', 'not-found');

Expand Down
6 changes: 2 additions & 4 deletions packages/shared/sdk-client/src/LDClientImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,9 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {

if (foundItem === undefined || foundItem.flag.deleted) {
const defVal = defaultValue ?? null;
const error = new LDClientError(
`Unknown feature flag "${flagKey}"; returning default value ${defVal}.`,
);

this.emitter.emit('error', this._activeContextTracker.getUnwrappedContext(), error);
this.logger?.warn(`Unknown feature flag "${flagKey}"; returning default value ${defVal}.`);

if (hasContext) {
this._eventProcessor?.sendEvent(
this._eventFactoryDefault.unknownFlagEvent(flagKey, defVal, evalContext),
Expand Down