From 37a3629b62ef814d5d0941a3505e93f4b04bb29c Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Wed, 17 Jul 2024 21:21:52 +0100 Subject: [PATCH] refactor: add error catching and silently error when push notifications fail in browsers we cannot fully determine if a user has push permissions. This ensures that notifications can still be created even if push notifications fail. --- .../NotificationServicesController.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts index 87573d62a9..f7d6747180 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts @@ -284,28 +284,40 @@ export default class NotificationServicesController extends BaseController< if (!this.#isPushIntegrated) { return; } - await this.messagingSystem.call( - 'NotificationServicesPushController:enablePushNotifications', - UUIDs, - ); + try { + await this.messagingSystem.call( + 'NotificationServicesPushController:enablePushNotifications', + UUIDs, + ); + } catch (e) { + log.error('Silently failed to enable push notifications', e); + } }, disablePushNotifications: async (UUIDs: string[]) => { if (!this.#isPushIntegrated) { return; } - await this.messagingSystem.call( - 'NotificationServicesPushController:disablePushNotifications', - UUIDs, - ); + try { + await this.messagingSystem.call( + 'NotificationServicesPushController:disablePushNotifications', + UUIDs, + ); + } catch (e) { + log.error('Silently failed to disable push notifications', e); + } }, updatePushNotifications: async (UUIDs: string[]) => { if (!this.#isPushIntegrated) { return; } - await this.messagingSystem.call( - 'NotificationServicesPushController:updateTriggerPushNotifications', - UUIDs, - ); + try { + await this.messagingSystem.call( + 'NotificationServicesPushController:updateTriggerPushNotifications', + UUIDs, + ); + } catch (e) { + log.error('Silently failed to update push notifications', e); + } }, subscribe: () => { if (!this.#isPushIntegrated) {