From 1ab20885df7d56882bd449fba93c42c49061c417 Mon Sep 17 00:00:00 2001 From: Brian Scherner Date: Wed, 20 Aug 2025 15:22:27 -0700 Subject: [PATCH 1/2] Improve error handling for adding contacts by making error messages user-friendly. --- src/components/Modals/AddContactModal.jsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/Modals/AddContactModal.jsx b/src/components/Modals/AddContactModal.jsx index f940e67c..7117162d 100644 --- a/src/components/Modals/AddContactModal.jsx +++ b/src/components/Modals/AddContactModal.jsx @@ -158,6 +158,20 @@ const AddContactModal = ({ setOIDC(e.target.value); }; + const getUserFriendlyError = (e) => { + if (e.status === 404 || (typeof e.message === 'string' && e.message.includes('404'))) { + return 'The contact could not be found in the pod. Please ensure the username is correct and registered with this pod.'; + } + if (e.status === 401 || (typeof e.message === 'string' && e.message.includes('401'))) { + return 'You are not authorized to add this contact. Please check your permissions.'; + } + if (typeof e.message === 'string' && e.message.toLowerCase().includes('network')) { + return 'Network error: Unable to reach the pod. Please check your connection and try again.'; + } + + return 'An unexpected error occurred while adding the contact. Please try again or contact support.'; + }; + const handleAddContact = async (event) => { event.preventDefault(); setProcessing(true); @@ -207,8 +221,8 @@ const AddContactModal = ({ setShowAddContactModal(false); clearInputFields(); } catch (e) { - const errorMessage = e ? e.message : 'Unknown error occurred'; - addNotification('error', `Add contact failed. Reason: ${errorMessage}`); + const errorMessage = getUserFriendlyError(e); + addNotification('error', `${errorMessage}`); setInvalidWebId(true); } finally { setProcessing(false); From 990aab1ab3ffb1bcc46f31bc9f012f98db0a2131 Mon Sep 17 00:00:00 2001 From: Brian Scherner Date: Wed, 20 Aug 2025 15:39:11 -0700 Subject: [PATCH 2/2] Improve error handling for readability and add logging statement. --- src/components/Modals/AddContactModal.jsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Modals/AddContactModal.jsx b/src/components/Modals/AddContactModal.jsx index 7117162d..7927240b 100644 --- a/src/components/Modals/AddContactModal.jsx +++ b/src/components/Modals/AddContactModal.jsx @@ -159,13 +159,18 @@ const AddContactModal = ({ }; const getUserFriendlyError = (e) => { - if (e.status === 404 || (typeof e.message === 'string' && e.message.includes('404'))) { + const status = e?.status || e?.response?.status; + const message = typeof e?.message === 'string' ? e.message : ''; + + console.error('Add contact error:', status, message, e); + + if (status === 404 || message.includes('404')) { return 'The contact could not be found in the pod. Please ensure the username is correct and registered with this pod.'; } - if (e.status === 401 || (typeof e.message === 'string' && e.message.includes('401'))) { + if (status === 401 || status === 403 || message.includes('401') || message.includes('403')) { return 'You are not authorized to add this contact. Please check your permissions.'; } - if (typeof e.message === 'string' && e.message.toLowerCase().includes('network')) { + if (message.toLowerCase().includes('network')) { return 'Network error: Unable to reach the pod. Please check your connection and try again.'; }