Skip to content

Commit 3da16bf

Browse files
authored
Remove outdated push subscription (#7080)
1 parent 4501a1c commit 3da16bf

File tree

1 file changed

+7
-3
lines changed
  • server-plugins/notification-resources/src

1 file changed

+7
-3
lines changed

server-plugins/notification-resources/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ export async function createPushNotification (
607607
}
608608
}
609609

610+
const errorMessages = ['expired', 'Unregistered', 'No such subscription']
611+
610612
async function sendPushToSubscription (
611613
control: TriggerControl,
612614
targetUser: Ref<Account>,
@@ -617,9 +619,11 @@ async function sendPushToSubscription (
617619
await webpush.sendNotification(subscription, JSON.stringify(data))
618620
} catch (err) {
619621
control.ctx.info('Cannot send push notification to', { user: targetUser, err })
620-
if (err instanceof WebPushError && err.body.includes('expired')) {
621-
const tx = control.txFactory.createTxRemoveDoc(subscription._class, subscription.space, subscription._id)
622-
await control.apply(control.ctx, [tx])
622+
if (err instanceof WebPushError) {
623+
if (errorMessages.some((p) => (err as WebPushError).body.includes(p))) {
624+
const tx = control.txFactory.createTxRemoveDoc(subscription._class, subscription.space, subscription._id)
625+
await control.apply(control.ctx, [tx])
626+
}
623627
}
624628
}
625629
}

0 commit comments

Comments
 (0)