Skip to content

Commit

Permalink
fix: Do not throw from newDefaultEventDispatcher on invalid key (#143)
Browse files Browse the repository at this point in the history
* fix: Do not throw from newDefaultEventDispatcher on invalid key

* version bump

* use info instead

* switch to debug log
  • Loading branch information
felipecsl authored Nov 27, 2024
1 parent 2251bf5 commit 6011607
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/js-client-sdk-common",
"version": "4.5.0",
"version": "4.5.1",
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)",
"main": "dist/index.js",
"files": [
Expand Down
16 changes: 8 additions & 8 deletions src/events/default-event-dispatcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DefaultEventDispatcher, {
} from './default-event-dispatcher';
import { Event } from './event-dispatcher';
import NetworkStatusListener from './network-status-listener';
import NoOpEventDispatcher from './no-op-event-dispatcher';

global.fetch = jest.fn();

Expand Down Expand Up @@ -201,14 +202,13 @@ describe('DefaultEventDispatcher', () => {
});

describe('newDefaultEventDispatcher', () => {
it('should throw if SDK key is invalid', () => {
expect(() => {
newDefaultEventDispatcher(
new ArrayBackedNamedEventQueue('test-queue'),
mockNetworkStatusListener,
'invalid-sdk-key',
);
}).toThrow('Unable to parse Event ingestion URL from SDK key');
it('should fallback to no-op dispatcher if SDK key is invalid', () => {
const eventDispatcher = newDefaultEventDispatcher(
new ArrayBackedNamedEventQueue('test-queue'),
mockNetworkStatusListener,
'invalid-sdk-key',
);
expect(eventDispatcher).toBeInstanceOf(NoOpEventDispatcher);
});

it('should create a new DefaultEventDispatcher with the provided configuration', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/events/default-event-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import EventDelivery from './event-delivery';
import EventDispatcher, { Event } from './event-dispatcher';
import NamedEventQueue from './named-event-queue';
import NetworkStatusListener from './network-status-listener';
import NoOpEventDispatcher from './no-op-event-dispatcher';
import SdkKeyDecoder from './sdk-key-decoder';

export type EventDispatcherConfig = {
Expand Down Expand Up @@ -135,7 +136,10 @@ export function newDefaultEventDispatcher(
const sdkKeyDecoder = new SdkKeyDecoder();
const ingestionUrl = sdkKeyDecoder.decodeEventIngestionHostName(sdkKey);
if (!ingestionUrl) {
throw new Error('Unable to parse Event ingestion URL from SDK key');
logger.debug(
'Unable to parse Event ingestion URL from SDK key, falling back to no-op event dispatcher',
);
return new NoOpEventDispatcher();
}
return new DefaultEventDispatcher(
new BatchEventProcessor(eventQueue, batchSize),
Expand Down

0 comments on commit 6011607

Please sign in to comment.