Better error handler for push notifications subscription

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-06-24 11:17:30 +02:00
parent ebe2e148d0
commit 54c23c6673
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
4 changed files with 17 additions and 10 deletions

View File

@ -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"
}

View File

@ -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"
}

View File

@ -33,14 +33,15 @@ export async function subscribeUserToPush(): Promise<PushSubscription | null> {
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;
}

View File

@ -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");