Skip to content

Commit

Permalink
Debugging service-worker (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
milenakrawczyk authored Oct 3, 2023
1 parent 917af70 commit d83a2fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ const unregisterServiceWorker = async () => {

const handlePushManagerSubscribe = async () => {
const serviceWorker = await navigator.serviceWorker.ready;

return await serviceWorker.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey,
});
try {
return await serviceWorker.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey,
});
} catch (e) {
console.error('Error while subscribing to service-worker.', e);
throw e;
}
};

export const handlePushManagerUnsubscribe = async (hide: () => void) => {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/notificationsLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export const setProcessSuccess = () => {
);
};

export const setProcessError = (error: unknown) => {
export const setProcessError = (error: any) => {
const accountIdLS = getLSAccountId();
const localStorageByAccountId = getNotificationLocalStorage();

const errorMessage = error.message ? error.message : 'unknown';
localStorage.setItem(
NOTIFICATIONS_STORAGE,
JSON.stringify({
Expand All @@ -85,11 +85,11 @@ export const setProcessError = (error: unknown) => {
...localStorageByAccountId,
permission: false,
subscribeStarted: false,
subscribeError: error,
subscribeError: errorMessage,
},
permission: false,
subscribeStarted: false,
subscribeError: error,
subscribeError: errorMessage,
}),
);
};
Expand Down

0 comments on commit d83a2fd

Please sign in to comment.