diff --git a/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/DeleteWorkspace/index.js b/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/DeleteWorkspace/index.js index 73eb691b4..3e696dbc9 100644 --- a/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/DeleteWorkspace/index.js +++ b/packages/bruno-app/src/components/Workspaces/WorkspaceConfigurer/DeleteWorkspace/index.js @@ -4,6 +4,7 @@ import Modal from 'components/Modal/index'; import { deleteWorkspace } from 'providers/ReduxStore/slices/workspaces/actions'; import { useDispatch } from 'react-redux'; import toast from 'react-hot-toast'; +import { toastError } from 'utils/common/error'; import StyledWrapper from './StyledWrapper'; const DeleteWorkspace = ({ onClose, workspace }) => { @@ -14,7 +15,7 @@ const DeleteWorkspace = ({ onClose, workspace }) => { toast.success('Workspace deleted!'); onClose(); }) - .catch(() => toast.error('An error occured while deleting the workspace')); + .catch(toastError); }; return ( diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js index a39b0fbde..ac0e559c9 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js @@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep'; import { workspaceSchema } from '@usebruno/schema'; import { findCollectionInWorkspace } from 'utils/workspaces'; import { getWorkspacesFromIdb, saveWorkspaceToIdb, deleteWorkspaceInIdb } from 'utils/idb/workspaces'; +import { BrunoError } from 'utils/common/error'; import { loadWorkspaces, addWorkspace as _addWorkspace, @@ -110,7 +111,7 @@ export const deleteWorkspace = (workspaceUid) => (dispatch, getState) => { return new Promise((resolve, reject) => { if (state.workspaces.activeWorkspaceUid === workspaceUid) { - throw new Error('User cannot delete current workspace'); + throw new BrunoError('Cannot delete current workspace'); } const workspace = find(state.workspaces.workspaces, (w) => w.uid === workspaceUid); diff --git a/packages/bruno-app/src/utils/common/error.js b/packages/bruno-app/src/utils/common/error.js index 6096099cd..e81e3fadc 100644 --- a/packages/bruno-app/src/utils/common/error.js +++ b/packages/bruno-app/src/utils/common/error.js @@ -9,26 +9,28 @@ export class BrunoError extends Error { } } -export const parseError = (error) => { +export const parseError = (error, defaultErrorMsg = 'An error occurred') => { if (error instanceof BrunoError) { return error.message; } - return error.message ? error.message : 'An error occured'; + return error.message ? error.message : defaultErrorMsg; }; -export const toastError = (error) => { +export const toastError = (error, defaultErrorMsg = 'An error occurred') => { + let errorMsg = parseError(error, defaultErrorMsg); + if (error instanceof BrunoError) { if (error.level === 'warning') { - return toast(error.message, { + return toast(errorMsg, { icon: '⚠️', duration: 3000 }); } - return toast.error(error.message, { + return toast.error(errorMsg, { duration: 3000 }); } - return toast.error(error.message || 'An error occured'); + return toast.error(errorMsg); }; diff --git a/packages/bruno-electron/package.json b/packages/bruno-electron/package.json index 008c20296..85ed2caf5 100644 --- a/packages/bruno-electron/package.json +++ b/packages/bruno-electron/package.json @@ -15,7 +15,6 @@ "dependencies": { "axios": "^0.26.0", "chokidar": "^3.5.3", - "dmg-license": "^1.0.11", "electron-is-dev": "^2.0.0", "electron-store": "^8.1.0", "electron-util": "^0.17.2", @@ -26,6 +25,9 @@ "nanoid": "3.3.4", "yup": "^0.32.11" }, + "optionalDependencies": { + "dmg-license": "^1.0.11" + }, "devDependencies": { "electron": "^21.1.1", "electron-builder": "23.0.2",