Skip to content

Commit 55004bf

Browse files
authored
fix: only inspect errors when fetched notifications exist (#1732)
Signed-off-by: Adam Setch <[email protected]>
1 parent f28182b commit 55004bf

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/renderer/hooks/useNotifications.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,26 @@ export const useNotifications = (): NotificationsState => {
7373
const fetchedNotifications = await getAllNotifications(state);
7474

7575
// Set Global Error if all accounts have the same error
76-
const allAccountsHaveErrors = fetchedNotifications.every((account) => {
77-
return account.error !== null;
78-
});
79-
let accountErrorsAreAllSame = true;
80-
const accountError = fetchedNotifications[0]?.error;
81-
for (const fetchedNotification of fetchedNotifications) {
82-
if (accountError !== fetchedNotification.error) {
83-
accountErrorsAreAllSame = false;
84-
break;
76+
if (fetchNotifications.length > 0) {
77+
const allAccountsHaveErrors = fetchedNotifications.every((account) => {
78+
return account.error !== null;
79+
});
80+
81+
let accountErrorsAreAllSame = true;
82+
const accountError = fetchedNotifications[0]?.error;
83+
84+
for (const fetchedNotification of fetchedNotifications) {
85+
if (accountError !== fetchedNotification.error) {
86+
accountErrorsAreAllSame = false;
87+
break;
88+
}
8589
}
86-
}
8790

88-
if (allAccountsHaveErrors) {
89-
setStatus('error');
90-
setGlobalError(accountErrorsAreAllSame ? accountError : null);
91-
return;
91+
if (allAccountsHaveErrors) {
92+
setStatus('error');
93+
setGlobalError(accountErrorsAreAllSame ? accountError : null);
94+
return;
95+
}
9296
}
9397

9498
setNotifications(fetchedNotifications);

0 commit comments

Comments
 (0)