Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/components/Modals/AddContactModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@
setOIDC(e.target.value);
};

const getUserFriendlyError = (e) => {
const status = e?.status || e?.response?.status;
const message = typeof e?.message === 'string' ? e.message : '';

console.error('Add contact error:', status, message, e);

Check warning on line 165 in src/components/Modals/AddContactModal.jsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement

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 (status === 401 || status === 403 || message.includes('401') || message.includes('403')) {
return 'You are not authorized to add this contact. Please check your permissions.';
}
if (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);
Expand Down Expand Up @@ -207,8 +226,8 @@
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);
Expand Down
Loading