Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/renderer/utils/api/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('renderer/utils/api/errors.ts', () => {
});

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

it('unknown error - unhandled 403', () => {
const mockError = new RequestError('Forbidden', 403, {
it('unknown error - unhandled 418', () => {
const mockError = new RequestError('Forbidden', 418, {
request: {
method: 'GET',
url: 'https://api.github.com',
Expand Down
40 changes: 20 additions & 20 deletions src/renderer/utils/api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ export function determineFailureType(
if (err instanceof RequestError) {
const status = err.status;

if (status === 401) {
return Errors.BAD_CREDENTIALS;
}

if (status === 403) {
if (message.includes("Missing the 'notifications' scope")) {
return Errors.MISSING_SCOPES;
}

if (
message.includes('API rate limit exceeded') ||
message.includes('You have exceeded a secondary rate limit')
) {
return Errors.RATE_LIMITED;
}
}

// Network-like errors for RequestError (no status or status 0)
if (status === 0 || status === undefined) {
return Errors.NETWORK;
switch (status) {
case 401:
return Errors.BAD_CREDENTIALS;
case 403:
if (message.includes("Missing the 'notifications' scope")) {
return Errors.MISSING_SCOPES;
}

if (
message.includes('API rate limit exceeded') ||
message.includes('You have exceeded a secondary rate limit')
) {
return Errors.RATE_LIMITED;
}

break;
case 500:
return Errors.NETWORK;
default:
break;
}
}

Expand Down