toast for duplicate name error caught on server

This commit is contained in:
Austin Spencer 2024-10-17 08:08:28 -04:00
parent b9772a024c
commit 3d9d3687d7
No known key found for this signature in database

View File

@ -116,6 +116,8 @@ export default {
this.newDevice.name = this.newDevice.name.trim() this.newDevice.name = this.newDevice.name.trim()
this.newDevice.email = this.newDevice.email.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.ereaderDevice) {
if (this.existingDevices.some((d) => d.name === this.newDevice.name)) { if (this.existingDevices.some((d) => d.name === this.newDevice.name)) {
this.$toast.error(this.$strings.ToastDeviceNameAlreadyExists) this.$toast.error(this.$strings.ToastDeviceNameAlreadyExists)
@ -154,7 +156,11 @@ export default {
}) })
.catch((error) => { .catch((error) => {
console.error('Failed to update device', 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(() => { .finally(() => {
this.processing = false this.processing = false
@ -180,7 +186,11 @@ export default {
}) })
.catch((error) => { .catch((error) => {
console.error('Failed to add device', 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(() => { .finally(() => {
this.processing = false this.processing = false