Fix error in checkSubscription and improve logging

This commit is contained in:
Karina Kwiatek 2023-01-03 17:32:21 +01:00 committed by Andreas Nedbal
parent 16b9262bed
commit 3033ad4400
1 changed files with 12 additions and 3 deletions

View File

@ -20,10 +20,19 @@ export function checkSubscription(subscription: PushSubscription): void {
},
contentType: 'application/json'
}).then(async response => {
const data = await response.json();
const data = await response.json;
if (data.status == 'subscribed') return;
if (data.status == 'failed') await unsubscribeServer(subscription);
if (data.status == 'subscribed') {
console.info('Push subscription is still valid.');
return;
}
if (data.status == 'failed') {
console.info('Pushing to this subscription failed too many times, unsubscribing.');
await unsubscribeServer(subscription);
}
console.info('Removing push subscription from this browser.');
await unsubscribeClient(subscription);
})
}