mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 01:14:23 +01:00
Improve error for workspace deletion (#39)
* Move dmg-license to optionalDependencies so it can be installed on windows * Extend toastError to accept a default error message * Throw BrunoError when in deleteWorkspace * Handle errors with the toastError * Use existing parseError for getting errorMsg in toastError
This commit is contained in:
parent
995c6b3fd0
commit
ea3a9394c9
@ -4,6 +4,7 @@ import Modal from 'components/Modal/index';
|
|||||||
import { deleteWorkspace } from 'providers/ReduxStore/slices/workspaces/actions';
|
import { deleteWorkspace } from 'providers/ReduxStore/slices/workspaces/actions';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
|
import { toastError } from 'utils/common/error';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
|
|
||||||
const DeleteWorkspace = ({ onClose, workspace }) => {
|
const DeleteWorkspace = ({ onClose, workspace }) => {
|
||||||
@ -14,7 +15,7 @@ const DeleteWorkspace = ({ onClose, workspace }) => {
|
|||||||
toast.success('Workspace deleted!');
|
toast.success('Workspace deleted!');
|
||||||
onClose();
|
onClose();
|
||||||
})
|
})
|
||||||
.catch(() => toast.error('An error occured while deleting the workspace'));
|
.catch(toastError);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep';
|
|||||||
import { workspaceSchema } from '@usebruno/schema';
|
import { workspaceSchema } from '@usebruno/schema';
|
||||||
import { findCollectionInWorkspace } from 'utils/workspaces';
|
import { findCollectionInWorkspace } from 'utils/workspaces';
|
||||||
import { getWorkspacesFromIdb, saveWorkspaceToIdb, deleteWorkspaceInIdb } from 'utils/idb/workspaces';
|
import { getWorkspacesFromIdb, saveWorkspaceToIdb, deleteWorkspaceInIdb } from 'utils/idb/workspaces';
|
||||||
|
import { BrunoError } from 'utils/common/error';
|
||||||
import {
|
import {
|
||||||
loadWorkspaces,
|
loadWorkspaces,
|
||||||
addWorkspace as _addWorkspace,
|
addWorkspace as _addWorkspace,
|
||||||
@ -110,7 +111,7 @@ export const deleteWorkspace = (workspaceUid) => (dispatch, getState) => {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (state.workspaces.activeWorkspaceUid === workspaceUid) {
|
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);
|
const workspace = find(state.workspaces.workspaces, (w) => w.uid === workspaceUid);
|
||||||
|
@ -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) {
|
if (error instanceof BrunoError) {
|
||||||
return error.message;
|
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 instanceof BrunoError) {
|
||||||
if (error.level === 'warning') {
|
if (error.level === 'warning') {
|
||||||
return toast(error.message, {
|
return toast(errorMsg, {
|
||||||
icon: '⚠️',
|
icon: '⚠️',
|
||||||
duration: 3000
|
duration: 3000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return toast.error(error.message, {
|
return toast.error(errorMsg, {
|
||||||
duration: 3000
|
duration: 3000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return toast.error(error.message || 'An error occured');
|
return toast.error(errorMsg);
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.26.0",
|
"axios": "^0.26.0",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
"dmg-license": "^1.0.11",
|
|
||||||
"electron-is-dev": "^2.0.0",
|
"electron-is-dev": "^2.0.0",
|
||||||
"electron-store": "^8.1.0",
|
"electron-store": "^8.1.0",
|
||||||
"electron-util": "^0.17.2",
|
"electron-util": "^0.17.2",
|
||||||
@ -26,6 +25,9 @@
|
|||||||
"nanoid": "3.3.4",
|
"nanoid": "3.3.4",
|
||||||
"yup": "^0.32.11"
|
"yup": "^0.32.11"
|
||||||
},
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"dmg-license": "^1.0.11"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "^21.1.1",
|
"electron": "^21.1.1",
|
||||||
"electron-builder": "23.0.2",
|
"electron-builder": "23.0.2",
|
||||||
|
Loading…
Reference in New Issue
Block a user