Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add exception handling to customer and contact delete #31

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 19 additions & 6 deletions frontend/src/pages/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,25 @@ async function deleteContact() {
theme: 'red',
variant: 'solid',
async onClick(close) {
await call('frappe.client.delete', {
doctype: 'Contact',
name: props.contactId,
})
close()
router.push({ name: 'Contacts' })
try {
await call('frappe.client.delete', {
doctype: 'Contact',
name: props.contactId,
})
close()
router.push({ name: 'Contacts' })
} catch (error) {
const errorMessage =
error.name === 'LinkExistsError' || error.message.includes('LinkExistsError')
? __('Cannot delete this contact because it is linked to other records.')
: __('Failed to delete the contact. Please try again later.');
createToast({
title: __('Error'),
text: errorMessage,
icon: 'x',
iconClasses: 'text-red-600',
});
}
},
},
],
Expand Down
25 changes: 19 additions & 6 deletions frontend/src/pages/Customer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,25 @@ async function deleteCustomer() {
theme: 'red',
variant: 'solid',
async onClick(close) {
await call('frappe.client.delete', {
doctype: 'Customer',
name: props.customerId,
})
close()
router.push({ name: 'Customers' })
try {
await call('frappe.client.delete', {
doctype: 'Customer',
name: props.customerId,
})
close()
router.push({ name: 'Customers' })
} catch (error) {
const errorMessage =
error.name === 'LinkExistsError' || error.message.includes('LinkExistsError')
? __('Cannot delete this customer because it is linked to other records.')
: __('Failed to delete the customer. Please try again later.');
createToast({
title: __('Error'),
text: errorMessage,
icon: 'x',
iconClasses: 'text-red-600',
});
}
},
},
],
Expand Down
25 changes: 19 additions & 6 deletions frontend/src/pages/MobileContact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,25 @@ async function deleteContact() {
theme: 'red',
variant: 'solid',
async onClick(close) {
await call('frappe.client.delete', {
doctype: 'Contact',
name: props.contactId,
})
close()
router.push({ name: 'Contacts' })
try {
await call('frappe.client.delete', {
doctype: 'Contact',
name: props.contactId,
})
close()
router.push({ name: 'Contacts' })
} catch (error) {
const errorMessage =
error.name === 'LinkExistsError' || error.message.includes('LinkExistsError')
? __('Cannot delete this contact because it is linked to other records.')
: __('Failed to delete the contact. Please try again later.');
createToast({
title: __('Error'),
text: errorMessage,
icon: 'x',
iconClasses: 'text-red-600',
});
}
},
},
],
Expand Down
25 changes: 19 additions & 6 deletions frontend/src/pages/MobileCustomer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,25 @@ async function deleteCustomer() {
theme: 'red',
variant: 'solid',
async onClick(close) {
await call('frappe.client.delete', {
doctype: 'Customer',
name: props.customerId,
})
close()
router.push({ name: 'Customers' })
try {
await call('frappe.client.delete', {
doctype: 'Customer',
name: props.customerId,
})
close()
router.push({ name: 'Customers' })
} catch (error) {
const errorMessage =
error.name === 'LinkExistsError' || error.message.includes('LinkExistsError')
? __('Cannot delete this customer because it is linked to other records.')
: __('Failed to delete the customer. Please try again later.');
createToast({
title: __('Error'),
text: errorMessage,
icon: 'x',
iconClasses: 'text-red-600',
});
}
},
},
],
Expand Down