Skip to content

Commit 61dd27c

Browse files
Merge pull request #706 from codeforpdx/Issue-697-Fix-Exception-Message
Make error messages user-friendly when adding contacts.
2 parents d3818ba + 990aab1 commit 61dd27c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/components/Modals/AddContactModal.jsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,25 @@ const AddContactModal = ({
158158
setOIDC(e.target.value);
159159
};
160160

161+
const getUserFriendlyError = (e) => {
162+
const status = e?.status || e?.response?.status;
163+
const message = typeof e?.message === 'string' ? e.message : '';
164+
165+
console.error('Add contact error:', status, message, e);
166+
167+
if (status === 404 || message.includes('404')) {
168+
return 'The contact could not be found in the pod. Please ensure the username is correct and registered with this pod.';
169+
}
170+
if (status === 401 || status === 403 || message.includes('401') || message.includes('403')) {
171+
return 'You are not authorized to add this contact. Please check your permissions.';
172+
}
173+
if (message.toLowerCase().includes('network')) {
174+
return 'Network error: Unable to reach the pod. Please check your connection and try again.';
175+
}
176+
177+
return 'An unexpected error occurred while adding the contact. Please try again or contact support.';
178+
};
179+
161180
const handleAddContact = async (event) => {
162181
event.preventDefault();
163182
setProcessing(true);
@@ -207,8 +226,8 @@ const AddContactModal = ({
207226
setShowAddContactModal(false);
208227
clearInputFields();
209228
} catch (e) {
210-
const errorMessage = e ? e.message : 'Unknown error occurred';
211-
addNotification('error', `Add contact failed. Reason: ${errorMessage}`);
229+
const errorMessage = getUserFriendlyError(e);
230+
addNotification('error', `${errorMessage}`);
212231
setInvalidWebId(true);
213232
} finally {
214233
setProcessing(false);

0 commit comments

Comments
 (0)