File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' ,
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments