Skip to content

Commit 6011607

Browse files
authored
fix: Do not throw from newDefaultEventDispatcher on invalid key (#143)
* fix: Do not throw from newDefaultEventDispatcher on invalid key * version bump * use info instead * switch to debug log
1 parent 2251bf5 commit 6011607

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.5.0",
3+
"version": "4.5.1",
44
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)",
55
"main": "dist/index.js",
66
"files": [

src/events/default-event-dispatcher.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import DefaultEventDispatcher, {
66
} from './default-event-dispatcher';
77
import { Event } from './event-dispatcher';
88
import NetworkStatusListener from './network-status-listener';
9+
import NoOpEventDispatcher from './no-op-event-dispatcher';
910

1011
global.fetch = jest.fn();
1112

@@ -201,14 +202,13 @@ describe('DefaultEventDispatcher', () => {
201202
});
202203

203204
describe('newDefaultEventDispatcher', () => {
204-
it('should throw if SDK key is invalid', () => {
205-
expect(() => {
206-
newDefaultEventDispatcher(
207-
new ArrayBackedNamedEventQueue('test-queue'),
208-
mockNetworkStatusListener,
209-
'invalid-sdk-key',
210-
);
211-
}).toThrow('Unable to parse Event ingestion URL from SDK key');
205+
it('should fallback to no-op dispatcher if SDK key is invalid', () => {
206+
const eventDispatcher = newDefaultEventDispatcher(
207+
new ArrayBackedNamedEventQueue('test-queue'),
208+
mockNetworkStatusListener,
209+
'invalid-sdk-key',
210+
);
211+
expect(eventDispatcher).toBeInstanceOf(NoOpEventDispatcher);
212212
});
213213

214214
it('should create a new DefaultEventDispatcher with the provided configuration', () => {

src/events/default-event-dispatcher.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import EventDelivery from './event-delivery';
66
import EventDispatcher, { Event } from './event-dispatcher';
77
import NamedEventQueue from './named-event-queue';
88
import NetworkStatusListener from './network-status-listener';
9+
import NoOpEventDispatcher from './no-op-event-dispatcher';
910
import SdkKeyDecoder from './sdk-key-decoder';
1011

1112
export type EventDispatcherConfig = {
@@ -135,7 +136,10 @@ export function newDefaultEventDispatcher(
135136
const sdkKeyDecoder = new SdkKeyDecoder();
136137
const ingestionUrl = sdkKeyDecoder.decodeEventIngestionHostName(sdkKey);
137138
if (!ingestionUrl) {
138-
throw new Error('Unable to parse Event ingestion URL from SDK key');
139+
logger.debug(
140+
'Unable to parse Event ingestion URL from SDK key, falling back to no-op event dispatcher',
141+
);
142+
return new NoOpEventDispatcher();
139143
}
140144
return new DefaultEventDispatcher(
141145
new BatchEventProcessor(eventQueue, batchSize),

0 commit comments

Comments
 (0)