Repository: gitify-app/gitify
Pull request #1506 (2024-09-02 13:09:00)

refactor: extract error constants
goal is to slowly working towards separating the gitify specific constants/types from the github (or other platform) constants/types


Patch:
diff --git a/package.json b/package.json
index 2e9e0867..8af75a9e 100644
--- a/package.json
+++ b/package.json
@@ -139,7 +139,7 @@
     "jest": "29.7.0",
     "jest-environment-jsdom": "29.7.0",
     "nock": "13.5.5",
-    "postcss": "8.4.43",
+    "postcss": "8.4.44",
     "postcss-loader": "8.1.1",
     "resize-observer-polyfill": "1.5.1",
     "rimraf": "6.0.1",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 107da8e6..66afcaf6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -95,7 +95,7 @@ importers:
         version: 5.3.3
       autoprefixer:
         specifier: 10.4.20
-        version: 10.4.20(postcss@8.4.43)
+        version: 10.4.20(postcss@8.4.44)
       css-loader:
         specifier: 7.1.2
         version: 7.1.2(webpack@5.94.0(webpack-cli@5.1.4))
@@ -121,11 +121,11 @@ importers:
         specifier: 13.5.5
         version: 13.5.5
       postcss:
-        specifier: 8.4.43
-        version: 8.4.43
+        specifier: 8.4.44
+        version: 8.4.44
       postcss-loader:
         specifier: 8.1.1
-        version: 8.1.1(postcss@8.4.43)(typescript@5.5.4)(webpack@5.94.0(webpack-cli@5.1.4))
+        version: 8.1.1(postcss@8.4.44)(typescript@5.5.4)(webpack@5.94.0(webpack-cli@5.1.4))
       resize-observer-polyfill:
         specifier: 1.5.1
         version: 1.5.1
@@ -2521,8 +2521,8 @@ packages:
   postcss-value-parser@4.2.0:
     resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==}
 
-  postcss@8.4.43:
-    resolution: {integrity: sha512-gJAQVYbh5R3gYm33FijzCZj7CHyQ3hWMgJMprLUlIYqCwTeZhBQ19wp0e9mA25BUbEvY5+EXuuaAjqQsrBxQBQ==}
+  postcss@8.4.44:
+    resolution: {integrity: sha512-Aweb9unOEpQ3ezu4Q00DPvvM2ZTUitJdNKeP/+uQgr1IBIqu574IaZoURId7BKtWMREwzKa9OgzPzezWGPWFQw==}
     engines: {node: ^10 || ^12 || >=14}
 
   pretty-format@27.5.1:
@@ -4255,14 +4255,14 @@ snapshots:
 
   at-least-node@1.0.0: {}
 
-  autoprefixer@10.4.20(postcss@8.4.43):
+  autoprefixer@10.4.20(postcss@8.4.44):
     dependencies:
       browserslist: 4.23.3
       caniuse-lite: 1.0.30001647
       fraction.js: 4.3.7
       normalize-range: 0.1.2
       picocolors: 1.0.1
-      postcss: 8.4.43
+      postcss: 8.4.44
       postcss-value-parser: 4.2.0
 
   axios@1.7.7:
@@ -4606,12 +4606,12 @@ snapshots:
 
   css-loader@7.1.2(webpack@5.94.0(webpack-cli@5.1.4)):
     dependencies:
-      icss-utils: 5.1.0(postcss@8.4.43)
-      postcss: 8.4.43
-      postcss-modules-extract-imports: 3.1.0(postcss@8.4.43)
-      postcss-modules-local-by-default: 4.0.5(postcss@8.4.43)
-      postcss-modules-scope: 3.2.0(postcss@8.4.43)
-      postcss-modules-values: 4.0.0(postcss@8.4.43)
+      icss-utils: 5.1.0(postcss@8.4.44)
+      postcss: 8.4.44
+      postcss-modules-extract-imports: 3.1.0(postcss@8.4.44)
+      postcss-modules-local-by-default: 4.0.5(postcss@8.4.44)
+      postcss-modules-scope: 3.2.0(postcss@8.4.44)
+      postcss-modules-values: 4.0.0(postcss@8.4.44)
       postcss-value-parser: 4.2.0
       semver: 7.6.0
     optionalDependencies:
@@ -5180,9 +5180,9 @@ snapshots:
     dependencies:
       safer-buffer: 2.1.2
 
-  icss-utils@5.1.0(postcss@8.4.43):
+  icss-utils@5.1.0(postcss@8.4.44):
     dependencies:
-      postcss: 8.4.43
+      postcss: 8.4.44
 
   ieee754@1.2.1: {}
 
@@ -5988,61 +5988,61 @@ snapshots:
       base64-js: 1.5.1
       xmlbuilder: 15.1.1
 
-  postcss-import@15.1.0(postcss@8.4.43):
+  postcss-import@15.1.0(postcss@8.4.44):
     dependencies:
-      postcss: 8.4.43
+      postcss: 8.4.44
       postcss-value-parser: 4.2.0
       read-cache: 1.0.0
       resolve: 1.22.8
 
-  postcss-js@4.0.1(postcss@8.4.43):
+  postcss-js@4.0.1(postcss@8.4.44):
     dependencies:
       camelcase-css: 2.0.1
-      postcss: 8.4.43
+      postcss: 8.4.44
 
-  postcss-load-config@4.0.2(postcss@8.4.43)(ts-node@10.9.2(@types/node@20.16.3)(typescript@5.5.4)):
+  postcss-load-config@4.0.2(postcss@8.4.44)(ts-node@10.9.2(@types/node@20.16.3)(typescript@5.5.4)):
     dependencies:
       lilconfig: 3.1.1
       yaml: 2.4.1
     optionalDependencies:
-      postcss: 8.4.43
+      postcss: 8.4.44
       ts-node: 10.9.2(@types/node@20.16.3)(typescript@5.5.4)
 
-  postcss-loader@8.1.1(postcss@8.4.43)(typescript@5.5.4)(webpack@5.94.0(webpack-cli@5.1.4)):
+  postcss-loader@8.1.1(postcss@8.4.44)(typescript@5.5.4)(webpack@5.94.0(webpack-cli@5.1.4)):
     dependencies:
       cosmiconfig: 9.0.0(typescript@5.5.4)
       jiti: 1.21.0
-      postcss: 8.4.43
+      postcss: 8.4.44
       semver: 7.6.0
     optionalDependencies:
       webpack: 5.94.0(webpack-cli@5.1.4)
     transitivePeerDependencies:
       - typescript
 
-  postcss-modules-extract-imports@3.1.0(postcss@8.4.43):
+  postcss-modules-extract-imports@3.1.0(postcss@8.4.44):
     dependencies:
-      postcss: 8.4.43
+      postcss: 8.4.44
 
-  postcss-modules-local-by-default@4.0.5(postcss@8.4.43):
+  postcss-modules-local-by-default@4.0.5(postcss@8.4.44):
     dependencies:
-      icss-utils: 5.1.0(postcss@8.4.43)
-      postcss: 8.4.43
+      icss-utils: 5.1.0(postcss@8.4.44)
+      postcss: 8.4.44
       postcss-selector-parser: 6.0.16
       postcss-value-parser: 4.2.0
 
-  postcss-modules-scope@3.2.0(postcss@8.4.43):
+  postcss-modules-scope@3.2.0(postcss@8.4.44):
     dependencies:
-      postcss: 8.4.43
+      postcss: 8.4.44
       postcss-selector-parser: 6.0.16
 
-  postcss-modules-values@4.0.0(postcss@8.4.43):
+  postcss-modules-values@4.0.0(postcss@8.4.44):
     dependencies:
-      icss-utils: 5.1.0(postcss@8.4.43)
-      postcss: 8.4.43
+      icss-utils: 5.1.0(postcss@8.4.44)
+      postcss: 8.4.44
 
-  postcss-nested@6.0.1(postcss@8.4.43):
+  postcss-nested@6.0.1(postcss@8.4.44):
     dependencies:
-      postcss: 8.4.43
+      postcss: 8.4.44
       postcss-selector-parser: 6.0.16
 
   postcss-selector-parser@6.0.16:
@@ -6052,7 +6052,7 @@ snapshots:
 
   postcss-value-parser@4.2.0: {}
 
-  postcss@8.4.43:
+  postcss@8.4.44:
     dependencies:
       nanoid: 3.3.7
       picocolors: 1.0.1
@@ -6433,11 +6433,11 @@ snapshots:
       normalize-path: 3.0.0
       object-hash: 3.0.0
       picocolors: 1.0.1
-      postcss: 8.4.43
-      postcss-import: 15.1.0(postcss@8.4.43)
-      postcss-js: 4.0.1(postcss@8.4.43)
-      postcss-load-config: 4.0.2(postcss@8.4.43)(ts-node@10.9.2(@types/node@20.16.3)(typescript@5.5.4))
-      postcss-nested: 6.0.1(postcss@8.4.43)
+      postcss: 8.4.44
+      postcss-import: 15.1.0(postcss@8.4.44)
+      postcss-js: 4.0.1(postcss@8.4.44)
+      postcss-load-config: 4.0.2(postcss@8.4.44)(ts-node@10.9.2(@types/node@20.16.3)(typescript@5.5.4))
+      postcss-nested: 6.0.1(postcss@8.4.44)
       postcss-selector-parser: 6.0.16
       resolve: 1.22.8
       sucrase: 3.35.0
diff --git a/src/__mocks__/partial-mocks.ts b/src/__mocks__/partial-mocks.ts
index 2d6023a8..5db97d31 100644
--- a/src/__mocks__/partial-mocks.ts
+++ b/src/__mocks__/partial-mocks.ts
@@ -1,6 +1,6 @@
 import type { Hostname, Link } from '../types';
 import type { Notification, Subject, User } from '../typesGitHub';
-import Constants from '../utils/constants';
+import { Constants } from '../utils/constants';
 import { mockGitifyUser, mockToken } from './state-mocks';
 
 export function partialMockNotification(
diff --git a/src/__mocks__/state-mocks.ts b/src/__mocks__/state-mocks.ts
index 12b3f638..616a3f40 100644
--- a/src/__mocks__/state-mocks.ts
+++ b/src/__mocks__/state-mocks.ts
@@ -12,7 +12,7 @@ import {
   type Token,
 } from '../types';
 import type { EnterpriseAccount } from '../utils/auth/types';
-import Constants from '../utils/constants';
+import { Constants } from '../utils/constants';
 
 export const mockEnterpriseAccounts: EnterpriseAccount[] = [
   {
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 6391d205..61f2f584 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -12,7 +12,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
 import { AppContext } from '../context/App';
 import { Size } from '../types';
 import { quitApp } from '../utils/comms';
-import Constants from '../utils/constants';
+import { Constants } from '../utils/constants';
 import { getFilterCount } from '../utils/helpers';
 import {
   openGitHubIssues,
diff --git a/src/components/settings/SystemSettings.tsx b/src/components/settings/SystemSettings.tsx
index 1d87ad3f..11eff641 100644
--- a/src/components/settings/SystemSettings.tsx
+++ b/src/components/settings/SystemSettings.tsx
@@ -2,7 +2,7 @@ import { DeviceDesktopIcon } from '@primer/octicons-react';
 import { type FC, useContext } from 'react';
 import { AppContext } from '../../context/App';
 import type { OpenPreference } from '../../types';
-import Constants from '../../utils/constants';
+import { Constants } from '../../utils/constants';
 import { isLinux, isMacOS } from '../../utils/platform';
 import { Checkbox } from '../fields/Checkbox';
 import { RadioGroup } from '../fields/RadioGroup';
diff --git a/src/context/App.tsx b/src/context/App.tsx
index eb93a8e9..2a878b68 100644
--- a/src/context/App.tsx
+++ b/src/context/App.tsx
@@ -41,7 +41,7 @@ import {
   setKeyboardShortcut,
   updateTrayTitle,
 } from '../utils/comms';
-import Constants from '../utils/constants';
+import { Constants } from '../utils/constants';
 import { getNotificationCount } from '../utils/notifications';
 import { clearState, loadState, saveState } from '../utils/storage';
 import { setTheme } from '../utils/theme';
diff --git a/src/routes/LoginWithOAuthApp.tsx b/src/routes/LoginWithOAuthApp.tsx
index 3d560b69..1e0cbbaf 100644
--- a/src/routes/LoginWithOAuthApp.tsx
+++ b/src/routes/LoginWithOAuthApp.tsx
@@ -21,7 +21,7 @@ import {
   isValidHostname,
   isValidToken,
 } from '../utils/auth/utils';
-import Constants from '../utils/constants';
+import { Constants } from '../utils/constants';
 
 interface IValues {
   hostname?: Hostname;
diff --git a/src/routes/Notifications.tsx b/src/routes/Notifications.tsx
index c92430ba..ab129c70 100644
--- a/src/routes/Notifications.tsx
+++ b/src/routes/Notifications.tsx
@@ -4,7 +4,7 @@ import { AllRead } from '../components/AllRead';
 import { Oops } from '../components/Oops';
 import { AppContext } from '../context/App';
 import { getAccountUUID } from '../utils/auth/utils';
-import { Errors } from '../utils/constants';
+import { Errors } from '../utils/errors';
 import { getNotificationCount } from '../utils/notifications';
 
 export const NotificationsRoute: FC = () => {
diff --git a/src/utils/api/errors.ts b/src/utils/api/errors.ts
index 7202d567..4f697614 100644
--- a/src/utils/api/errors.ts
+++ b/src/utils/api/errors.ts
@@ -1,7 +1,7 @@
 import { AxiosError } from 'axios';
 import type { GitifyError } from '../../types';
 import type { GitHubRESTError } from '../../typesGitHub';
-import { Errors } from '../constants';
+import { Errors } from '../errors';
 
 export function determineFailureType(
   err: AxiosError<GitHubRESTError>,
diff --git a/src/utils/api/utils.ts b/src/utils/api/utils.ts
index 644d9f33..9ad0e966 100644
--- a/src/utils/api/utils.ts
+++ b/src/utils/api/utils.ts
@@ -1,5 +1,5 @@
 import type { Hostname } from '../../types';
-import Constants from '../constants';
+import { Constants } from '../constants';
 import { isEnterpriseServerHost } from '../helpers';
 
 export function getGitHubAPIBaseUrl(hostname: Hostname): URL {
diff --git a/src/utils/auth/migration.ts b/src/utils/auth/migration.ts
index 643edcb3..87b32e67 100644
--- a/src/utils/auth/migration.ts
+++ b/src/utils/auth/migration.ts
@@ -1,6 +1,6 @@
 import log from 'electron-log';
 import type { Account, AuthState } from '../../types';
-import Constants from '../constants';
+import { Constants } from '../constants';
 import { loadState, saveState } from '../storage';
 import { getUserData } from './utils';
 
diff --git a/src/utils/comms.ts b/src/utils/comms.ts
index 0a11fa0c..03266e60 100644
--- a/src/utils/comms.ts
+++ b/src/utils/comms.ts
@@ -1,7 +1,7 @@
 import { ipcRenderer, shell } from 'electron';
 import { defaultSettings } from '../context/App';
 import { type Link, OpenPreference } from '../types';
-import Constants from './constants';
+import { Constants } from './constants';
 import { loadState } from './storage';
 
 export function openExternalLink(url: Link): void {
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index eabacbae..1d95d155 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -1,4 +1,4 @@
-import type { ErrorType, GitifyError, Link } from '../types';
+import type { Link } from '../types';
 import type { ClientID, ClientSecret, Hostname } from '../types';
 
 export const Constants = {
@@ -36,36 +36,3 @@ export const Constants = {
       'https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/setting-up-notifications/configuring-notifications#about-participating-and-watching-notifications' as Link,
   },
 };
-
-export const Errors: Record<ErrorType, GitifyError> = {
-  BAD_CREDENTIALS: {
-    title: 'Bad Credentials',
-    descriptions: ['Your credentials are either invalid or expired.'],
-    emojis: ['🔓'],
-  },
-  MISSING_SCOPES: {
-    title: 'Missing Scopes',
-    descriptions: ['Your credentials are missing a required API scope.'],
-    emojis: ['🔭'],
-  },
-  NETWORK: {
-    title: 'Network Error',
-    descriptions: [
-      'Unable to connect to one or more of your GitHub environments.',
-      'Please check your network connection, including whether you require a VPN, and try again.',
-    ],
-    emojis: ['🛜'],
-  },
-  RATE_LIMITED: {
-    title: 'Rate Limited',
-    descriptions: ['Please wait a while before trying again.'],
-    emojis: ['😮‍💨'],
-  },
-  UNKNOWN: {
-    title: 'Oops! Something went wrong',
-    descriptions: ['Please try again later.'],
-    emojis: ['🤔', '🥲', '😳', '🫠', '🙃', '🙈'],
-  },
-};
-
-export default Constants;
diff --git a/src/utils/errors.ts b/src/utils/errors.ts
new file mode 100644
index 00000000..e83ee5c7
--- /dev/null
+++ b/src/utils/errors.ts
@@ -0,0 +1,32 @@
+import type { ErrorType, GitifyError } from '../types';
+
+export const Errors: Record<ErrorType, GitifyError> = {
+  BAD_CREDENTIALS: {
+    title: 'Bad Credentials',
+    descriptions: ['Your credentials are either invalid or expired.'],
+    emojis: ['🔓'],
+  },
+  MISSING_SCOPES: {
+    title: 'Missing Scopes',
+    descriptions: ['Your credentials are missing a required API scope.'],
+    emojis: ['🔭'],
+  },
+  NETWORK: {
+    title: 'Network Error',
+    descriptions: [
+      'Unable to connect to one or more of your GitHub environments.',
+      'Please check your network connection, including whether you require a VPN, and try again.',
+    ],
+    emojis: ['🛜'],
+  },
+  RATE_LIMITED: {
+    title: 'Rate Limited',
+    descriptions: ['Please wait a while before trying again.'],
+    emojis: ['😮‍💨'],
+  },
+  UNKNOWN: {
+    title: 'Oops! Something went wrong',
+    descriptions: ['Please try again later.'],
+    emojis: ['🤔', '🥲', '😳', '🫠', '🙃', '🙈'],
+  },
+};
diff --git a/src/utils/links.ts b/src/utils/links.ts
index e19aaadd..28b84d03 100644
--- a/src/utils/links.ts
+++ b/src/utils/links.ts
@@ -2,7 +2,7 @@ import type { Account, Hostname, Link } from '../types';
 import type { Notification, Repository, SubjectUser } from '../typesGitHub';
 import { getDeveloperSettingsURL } from './auth/utils';
 import { openExternalLink } from './comms';
-import Constants from './constants';
+import { Constants } from './constants';
 import { generateGitHubWebUrl } from './helpers';
 
 export function openGitifyRepository() {


Test patch:
diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx
index 3c7fe43b..2ec7f666 100644
--- a/src/context/App.test.tsx
+++ b/src/context/App.test.tsx
@@ -6,7 +6,7 @@ import type { AuthState, Hostname, SettingsState, Token } from '../types';
 import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks';
 import * as apiRequests from '../utils/api/request';
 import * as comms from '../utils/comms';
-import Constants from '../utils/constants';
+import { Constants } from '../utils/constants';
 import * as notifications from '../utils/notifications';
 import * as storage from '../utils/storage';
 import { AppContext, AppProvider, defaultSettings } from './App';
diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts
index 1b014a12..82c020fa 100644
--- a/src/hooks/useNotifications.test.ts
+++ b/src/hooks/useNotifications.test.ts
@@ -13,7 +13,7 @@ import {
   mockNotificationUser,
   mockSingleNotification,
 } from '../utils/api/__mocks__/response-mocks';
-import { Errors } from '../utils/constants';
+import { Errors } from '../utils/errors';
 import { useNotifications } from './useNotifications';
 
 describe('hooks/useNotifications.ts', () => {
diff --git a/src/routes/Notifications.test.tsx b/src/routes/Notifications.test.tsx
index f883bcc4..f61e78f2 100644
--- a/src/routes/Notifications.test.tsx
+++ b/src/routes/Notifications.test.tsx
@@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
 import { mockAccountNotifications } from '../__mocks__/notifications-mocks';
 import { mockSettings } from '../__mocks__/state-mocks';
 import { AppContext } from '../context/App';
-import { Errors } from '../utils/constants';
+import { Errors } from '../utils/errors';
 import { NotificationsRoute } from './Notifications';
 
 jest.mock('../components/AccountNotifications', () => ({
diff --git a/src/utils/api/errors.test.ts b/src/utils/api/errors.test.ts
index 792d31b1..8764a460 100644
--- a/src/utils/api/errors.test.ts
+++ b/src/utils/api/errors.test.ts
@@ -1,7 +1,7 @@
 import { AxiosError, type AxiosResponse } from 'axios';
 import type { Link } from '../../types';
 import type { GitHubRESTError } from '../../typesGitHub';
-import { Errors } from '../constants';
+import { Errors } from '../errors';
 import { determineFailureType } from './errors';
 
 describe('utils/api/errors.ts', () => {
diff --git a/src/utils/auth/migration.test.ts b/src/utils/auth/migration.test.ts
index b6669d37..2ab67b75 100644
--- a/src/utils/auth/migration.test.ts
+++ b/src/utils/auth/migration.test.ts
@@ -3,7 +3,7 @@ import log from 'electron-log';
 import nock from 'nock';
 import { mockGitifyUser, mockToken } from '../../__mocks__/state-mocks';
 import type { AuthState, Hostname } from '../../types';
-import Constants from '../constants';
+import { Constants } from '../constants';
 import {
   convertAccounts,
   hasAccountsToMigrate,
diff --git a/src/utils/links.test.ts b/src/utils/links.test.ts
index d4c4f656..1ea209ea 100644
--- a/src/utils/links.test.ts
+++ b/src/utils/links.test.ts
@@ -5,7 +5,7 @@ import type { Repository } from '../typesGitHub';
 import { mockSingleNotification } from './api/__mocks__/response-mocks';
 import * as authUtils from './auth/utils';
 import * as comms from './comms';
-import Constants from './constants';
+import { Constants } from './constants';
 import * as helpers from './helpers';
 import {
   openAccountProfile,
diff --git a/src/utils/storage.test.ts b/src/utils/storage.test.ts
index 41794ce8..46d59c6c 100644
--- a/src/utils/storage.test.ts
+++ b/src/utils/storage.test.ts
@@ -1,6 +1,6 @@
 import { mockSettings } from '../__mocks__/state-mocks';
 import type { Token } from '../types';
-import Constants from './constants';
+import { Constants } from './constants';
 import { clearState, loadState, saveState } from './storage';
 
 describe('utils/storage.ts', () => {