From 3b273b0fa6277fc4587aff1dfede705a86d3f861 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 18 Jan 2025 08:48:11 -0500 Subject: [PATCH] fix: only inspect errors when fetched notifications exist Signed-off-by: Adam Setch --- src/renderer/hooks/useNotifications.ts | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/renderer/hooks/useNotifications.ts b/src/renderer/hooks/useNotifications.ts index f57b35108..d75d0b9b0 100644 --- a/src/renderer/hooks/useNotifications.ts +++ b/src/renderer/hooks/useNotifications.ts @@ -73,22 +73,26 @@ export const useNotifications = (): NotificationsState => { const fetchedNotifications = await getAllNotifications(state); // Set Global Error if all accounts have the same error - const allAccountsHaveErrors = fetchedNotifications.every((account) => { - return account.error !== null; - }); - let accountErrorsAreAllSame = true; - const accountError = fetchedNotifications[0]?.error; - for (const fetchedNotification of fetchedNotifications) { - if (accountError !== fetchedNotification.error) { - accountErrorsAreAllSame = false; - break; + if (fetchNotifications.length > 0) { + const allAccountsHaveErrors = fetchedNotifications.every((account) => { + return account.error !== null; + }); + + let accountErrorsAreAllSame = true; + const accountError = fetchedNotifications[0]?.error; + + for (const fetchedNotification of fetchedNotifications) { + if (accountError !== fetchedNotification.error) { + accountErrorsAreAllSame = false; + break; + } } - } - if (allAccountsHaveErrors) { - setStatus('error'); - setGlobalError(accountErrorsAreAllSame ? accountError : null); - return; + if (allAccountsHaveErrors) { + setStatus('error'); + setGlobalError(accountErrorsAreAllSame ? accountError : null); + return; + } } setNotifications(fetchedNotifications);