From 8bac0e31ebdee69da583e7fedbc0f8cd70722bdd Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Tue, 6 Aug 2024 13:19:09 -0700 Subject: [PATCH] Handle unknown subscription notification received --- src/messages/message-mediator.ts | 1 + src/subscription-handler.spec.ts | 7 +++++-- src/subscription-handler.ts | 7 ++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/messages/message-mediator.ts b/src/messages/message-mediator.ts index 649a816..5d632c9 100644 --- a/src/messages/message-mediator.ts +++ b/src/messages/message-mediator.ts @@ -121,6 +121,7 @@ export class MessageMediator { } ack(ack: ClientMessageAck) { + this.logger.debug("Queuing ack", ack); this.ackQueue.push(ack); } diff --git a/src/subscription-handler.spec.ts b/src/subscription-handler.spec.ts index c1dc61e..0c5265a 100644 --- a/src/subscription-handler.spec.ts +++ b/src/subscription-handler.spec.ts @@ -67,11 +67,14 @@ describe("SubscriptionManager", () => { it("gets a subscription", () => { const subscription = manager.get(channelID); + if (!subscription) { + fail("Subscription not found"); + } expect(subscription["endpoint"].toString()).toEqual(endpoint); }); - it("throws when subscription is not found", () => { - expect(() => manager.get(newUuid())).toThrow("Subscription not found"); + it("is null when subscription is not found", () => { + expect(manager.get(newUuid())).toBeNull(); }); }); diff --git a/src/subscription-handler.ts b/src/subscription-handler.ts index 59596ce..6e535f1 100644 --- a/src/subscription-handler.ts +++ b/src/subscription-handler.ts @@ -55,12 +55,9 @@ export class SubscriptionHandler { return [...this.subscriptions.keys()]; } - get(channelID: Uuid) { + get(channelID: Uuid): GenericPushSubscription | null { const sub = this.subscriptions.get(channelID); - if (!sub) { - throw new Error("Subscription not found"); - } - return sub; + return sub ?? null; } getByApplicationServerKey(applicationServerKey: string): GenericPushSubscription | undefined {