From 54c23c66736540f758be233fcfe53c0acbad8f19 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 24 Jun 2021 11:17:30 +0200 Subject: [PATCH] Better error handler for push notifications subscription Signed-off-by: Thomas Citharel --- js/src/i18n/en_US.json | 3 ++- js/src/i18n/fr_FR.json | 3 ++- js/src/services/push-subscription.ts | 17 +++++++++-------- js/src/views/Settings/Notifications.vue | 4 ++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/js/src/i18n/en_US.json b/js/src/i18n/en_US.json index b370a2fa0..01622cc95 100644 --- a/js/src/i18n/en_US.json +++ b/js/src/i18n/en_US.json @@ -1053,5 +1053,6 @@ "An error has occured while refreshing the page.": "An error has occured while refreshing the page.", "Join group {group}": "Join group {group}", "Public preview": "Public preview", - "On {instance} and other federated instances": "On {instance} and other federated instances" + "On {instance} and other federated instances": "On {instance} and other federated instances", + "Error while subscribing to push notifications": "Error while subscribing to push notifications" } diff --git a/js/src/i18n/fr_FR.json b/js/src/i18n/fr_FR.json index f9f94422c..3462a17e6 100644 --- a/js/src/i18n/fr_FR.json +++ b/js/src/i18n/fr_FR.json @@ -1144,5 +1144,6 @@ "An error has occured while refreshing the page.": "Une erreur est survenue lors du rafraîchissement de la page.", "Join group {group}": "Rejoindre le groupe {group}", "Public preview": "Aperçu public", - "On {instance} and other federated instances": "Sur {instance} et d'autres instances fédérées" + "On {instance} and other federated instances": "Sur {instance} et d'autres instances fédérées", + "Error while subscribing to push notifications": "Erreur lors de la souscriptions aux notifications push" } diff --git a/js/src/services/push-subscription.ts b/js/src/services/push-subscription.ts index afa711ba4..738ecc54c 100644 --- a/js/src/services/push-subscription.ts +++ b/js/src/services/push-subscription.ts @@ -33,14 +33,15 @@ export async function subscribeUserToPush(): Promise { data?.config?.webPush?.publicKey ), }; - const pushSubscription = await registration.pushManager.subscribe( - subscribeOptions - ); - console.log( - "Received PushSubscription: ", - JSON.stringify(pushSubscription) - ); - return pushSubscription; + try { + const pushSubscription = await registration.pushManager.subscribe( + subscribeOptions + ); + console.debug("Received PushSubscription: ", pushSubscription); + return pushSubscription; + } catch (e) { + console.error("Error while subscribing to push notifications", e); + } } return null; } diff --git a/js/src/views/Settings/Notifications.vue b/js/src/views/Settings/Notifications.vue index 99711c055..a4b127c50 100644 --- a/js/src/views/Settings/Notifications.vue +++ b/js/src/views/Settings/Notifications.vue @@ -597,6 +597,10 @@ export default class Notifications extends Vue { }); this.subscribed = true; console.log(data); + } else { + this.$notifier.error( + this.$t("Error while subscribing to push notifications") as string + ); } } else { console.log("can't do webpush");