From 3d9d3687d715d05b745d0e136879d0d166ba319e Mon Sep 17 00:00:00 2001 From: Austin Spencer Date: Thu, 17 Oct 2024 08:08:28 -0400 Subject: [PATCH] toast for duplicate name error caught on server --- .../modals/emails/UserEReaderDeviceModal.vue | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/components/modals/emails/UserEReaderDeviceModal.vue b/client/components/modals/emails/UserEReaderDeviceModal.vue index 1ad0ca36f..fe782dbf6 100644 --- a/client/components/modals/emails/UserEReaderDeviceModal.vue +++ b/client/components/modals/emails/UserEReaderDeviceModal.vue @@ -116,6 +116,8 @@ export default { this.newDevice.name = this.newDevice.name.trim() this.newDevice.email = this.newDevice.email.trim() + // Only catches duplicate names for the current user + // Duplicates with other users caught on server side if (!this.ereaderDevice) { if (this.existingDevices.some((d) => d.name === this.newDevice.name)) { this.$toast.error(this.$strings.ToastDeviceNameAlreadyExists) @@ -154,7 +156,11 @@ export default { }) .catch((error) => { console.error('Failed to update device', error) - this.$toast.error(this.$strings.ToastFailedToUpdate) + if (error.response?.data?.toLowerCase().includes('duplicate')) { + this.$toast.error(this.$strings.ToastDeviceNameAlreadyExists) + } else { + this.$toast.error(this.$strings.ToastDeviceAddFailed) + } }) .finally(() => { this.processing = false @@ -180,7 +186,11 @@ export default { }) .catch((error) => { console.error('Failed to add device', error) - this.$toast.error(this.$strings.ToastDeviceAddFailed) + if (error.response?.data?.toLowerCase().includes('duplicate')) { + this.$toast.error(this.$strings.ToastDeviceNameAlreadyExists) + } else { + this.$toast.error(this.$strings.ToastDeviceAddFailed) + } }) .finally(() => { this.processing = false