( err: Error | RequestError | GraphqlResponseError<unknown>, )
| 16 | * @returns The Gitify error type |
| 17 | */ |
| 18 | export function determineFailureType( |
| 19 | err: Error | RequestError | GraphqlResponseError<unknown>, |
| 20 | ): GitifyError { |
| 21 | const message = err.message || ''; |
| 22 | |
| 23 | // Check for safe storage decryption failures first (happens before API call) |
| 24 | if (message.includes(EVENTS.SAFE_STORAGE_DECRYPT)) { |
| 25 | return Errors.BAD_CREDENTIALS; |
| 26 | } |
| 27 | |
| 28 | // Handle Octokit REST RequestError |
| 29 | if (err instanceof RequestError) { |
| 30 | const status = err.status; |
| 31 | |
| 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; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Handle Octokit GraphQL GraphqlResponseError |
| 56 | if (err instanceof GraphqlResponseError) { |
| 57 | const errorMessages = |
| 58 | err.errors?.map((e) => e.message).join('; ') || message; |
| 59 | |
| 60 | if (errorMessages.includes('Bad credentials')) { |
| 61 | return Errors.BAD_CREDENTIALS; |
| 62 | } |
| 63 | |
| 64 | if ( |
| 65 | errorMessages.includes('API rate limit exceeded') || |
| 66 | errorMessages.includes('You have exceeded a secondary rate limit') |
| 67 | ) { |
| 68 | return Errors.RATE_LIMITED; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return Errors.UNKNOWN; |
| 73 | } |
| 74 | |
| 75 | /** |
no outgoing calls
no test coverage detected