From 5c04f884e29d80e246361b8156c4a2f91a5832b0 Mon Sep 17 00:00:00 2001 From: Sanjai Kumar <84461672+sanjai0py@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:24:25 +0530 Subject: [PATCH] refactor: Handle errors when importing collections (#2455) --- .../src/components/Sidebar/TitleBar/index.js | 15 +++++++++++---- .../bruno-app/src/components/Welcome/index.js | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/bruno-app/src/components/Sidebar/TitleBar/index.js b/packages/bruno-app/src/components/Sidebar/TitleBar/index.js index 7962da07f..bec0c92a5 100644 --- a/packages/bruno-app/src/components/Sidebar/TitleBar/index.js +++ b/packages/bruno-app/src/components/Sidebar/TitleBar/index.js @@ -31,10 +31,17 @@ const TitleBar = () => { }; const handleImportCollectionLocation = (collectionLocation) => { - dispatch(importCollection(importedCollection, collectionLocation)); - setImportCollectionLocationModalOpen(false); - setImportedCollection(null); - toast.success('Collection imported successfully'); + dispatch(importCollection(importedCollection, collectionLocation)) + .then(() => { + setImportCollectionLocationModalOpen(false); + setImportedCollection(null); + toast.success('Collection imported successfully'); + }) + .catch((err) => { + setImportCollectionLocationModalOpen(false); + console.error(err); + toast.error('An error occurred while importing the collection. Check the logs for more information.'); + }); }; const menuDropdownTippyRef = useRef(); diff --git a/packages/bruno-app/src/components/Welcome/index.js b/packages/bruno-app/src/components/Welcome/index.js index 7f60377b6..385a71486 100644 --- a/packages/bruno-app/src/components/Welcome/index.js +++ b/packages/bruno-app/src/components/Welcome/index.js @@ -34,10 +34,17 @@ const Welcome = () => { }; const handleImportCollectionLocation = (collectionLocation) => { - dispatch(importCollection(importedCollection, collectionLocation)); - setImportCollectionLocationModalOpen(false); - setImportedCollection(null); - toast.success('Collection imported successfully'); + dispatch(importCollection(importedCollection, collectionLocation)) + .then(() => { + setImportCollectionLocationModalOpen(false); + setImportedCollection(null); + toast.success('Collection imported successfully'); + }) + .catch((err) => { + setImportCollectionLocationModalOpen(false); + console.error(err); + toast.error('An error occurred while importing the collection. Check the logs for more information.'); + }); }; return (