Skip to content

Commit

Permalink
Handle unknown subscription notification received
Browse files Browse the repository at this point in the history
  • Loading branch information
MGibson1 committed Aug 6, 2024
1 parent b515e07 commit 8bac0e3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/messages/message-mediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class MessageMediator {
}

ack(ack: ClientMessageAck) {
this.logger.debug("Queuing ack", ack);
this.ackQueue.push(ack);
}

Expand Down
7 changes: 5 additions & 2 deletions src/subscription-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down
7 changes: 2 additions & 5 deletions src/subscription-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8bac0e3

Please sign in to comment.