diff --git a/src/renderer/utils/api/errors.test.ts b/src/renderer/utils/api/errors.test.ts index c3df40115..119466861 100644 --- a/src/renderer/utils/api/errors.test.ts +++ b/src/renderer/utils/api/errors.test.ts @@ -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', @@ -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', diff --git a/src/renderer/utils/api/errors.ts b/src/renderer/utils/api/errors.ts index 7bf00f0a8..ae80b3f4d 100644 --- a/src/renderer/utils/api/errors.ts +++ b/src/renderer/utils/api/errors.ts @@ -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; } }