Skip to content

Commit 94ecf7b

Browse files
committed
Merge branch 'main' into fix/inbox-flicker-during-loading
Signed-off-by: Adam Setch <adam.setch@outlook.com>
2 parents 882fa82 + 2815fd1 commit 94ecf7b

4 files changed

Lines changed: 31 additions & 26 deletions

File tree

src/renderer/hooks/useNotifications.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useMemo, useState } from 'react';
1+
import { useCallback, useMemo, useRef, useState } from 'react';
22

33
import type {
44
Account,
@@ -94,8 +94,14 @@ export const useNotifications = (): NotificationsState => {
9494
[notifications],
9595
);
9696

97+
const isFetchingRef = useRef(false);
9798
const fetchNotifications = useCallback(
9899
async (state: GitifyState) => {
100+
if (isFetchingRef.current) {
101+
// Prevent overlapping fetches
102+
return;
103+
}
104+
isFetchingRef.current = true;
99105
setStatus('loading');
100106
try {
101107
const previousNotifications = notifications;

src/renderer/utils/api/errors.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('renderer/utils/api/errors.ts', () => {
8383
});
8484

8585
it('network error - no status', () => {
86-
const mockError = new RequestError('Network error', 0, {
86+
const mockError = new RequestError('Network error', 500, {
8787
request: {
8888
method: 'GET',
8989
url: 'https://api.github.com',
@@ -94,8 +94,8 @@ describe('renderer/utils/api/errors.ts', () => {
9494
expect(result).toBe(Errors.NETWORK);
9595
});
9696

97-
it('unknown error - unhandled 403', () => {
98-
const mockError = new RequestError('Forbidden', 403, {
97+
it('unknown error - unhandled 418', () => {
98+
const mockError = new RequestError('Forbidden', 418, {
9999
request: {
100100
method: 'GET',
101101
url: 'https://api.github.com',

src/renderer/utils/api/errors.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ export function determineFailureType(
2929
if (err instanceof RequestError) {
3030
const status = err.status;
3131

32-
if (status === 401) {
33-
return Errors.BAD_CREDENTIALS;
34-
}
35-
36-
if (status === 403) {
37-
if (message.includes("Missing the 'notifications' scope")) {
38-
return Errors.MISSING_SCOPES;
39-
}
40-
41-
if (
42-
message.includes('API rate limit exceeded') ||
43-
message.includes('You have exceeded a secondary rate limit')
44-
) {
45-
return Errors.RATE_LIMITED;
46-
}
47-
}
48-
49-
// Network-like errors for RequestError (no status or status 0)
50-
if (status === 0 || status === undefined) {
51-
return Errors.NETWORK;
32+
switch (status) {
33+
case 401:
34+
return Errors.BAD_CREDENTIALS;
35+
case 403:
36+
if (message.includes("Missing the 'notifications' scope")) {
37+
return Errors.MISSING_SCOPES;
38+
}
39+
40+
if (
41+
message.includes('API rate limit exceeded') ||
42+
message.includes('You have exceeded a secondary rate limit')
43+
) {
44+
return Errors.RATE_LIMITED;
45+
}
46+
47+
break;
48+
case 500:
49+
return Errors.NETWORK;
50+
default:
51+
break;
5252
}
5353
}
5454

src/renderer/utils/api/octokit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ export async function createOctokitClientUncached(
8383
baseUrl: baseUrl,
8484
userAgent: userAgent,
8585
retry: {
86-
doNotRetry: ['400', '401', '403', '404', '422'],
87-
retries: 3,
86+
retries: 1,
8887
},
8988
});
9089
}

0 commit comments

Comments
 (0)