From 86e1a8729172aa03b20102937d8d17bfb5e05d4d Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Fri, 10 Jan 2025 03:35:04 +1030 Subject: [PATCH] refactor: streamline profile creation and update error handling for improved clarity --- .../src/components/profile/ProfileModal.jsx | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/profile/ProfileModal.jsx b/frontend/src/components/profile/ProfileModal.jsx index 0213050..815dbed 100644 --- a/frontend/src/components/profile/ProfileModal.jsx +++ b/frontend/src/components/profile/ProfileModal.jsx @@ -407,29 +407,17 @@ function ProfileModal({ if (isCloning || !initialProfile) { // Creating new profile - const result = await Profiles.create(profileData); - if (result.success === false) { - Alert.error(result.message); - setError(result.message); - return; - } + await Profiles.create(profileData); Alert.success('Profile created successfully'); } else { // Updating existing profile const originalName = initialProfile.content.name; const isNameChanged = originalName !== name; - - const result = await Profiles.update( + await Profiles.update( initialProfile.file_name.replace('.yml', ''), profileData, isNameChanged ? name : undefined ); - - if (result.success === false) { - Alert.error(result.message); - setError(result.message); - return; - } Alert.success('Profile updated successfully'); } @@ -437,8 +425,10 @@ function ProfileModal({ onClose(); } catch (error) { console.error('Error saving profile:', error); - Alert.error('An unexpected error occurred'); - setError('An unexpected error occurred'); + const errorMessage = + error.message || 'An unexpected error occurred'; + Alert.error(errorMessage); + setError(errorMessage); } };