fix(users): show normalized errors when bulk updating limits

This commit is contained in:
chihao.ou
2026-09-30 02:20:13 +08:00
parent a60a29549f
commit e180a939ac
2 changed files with 23 additions and 3 deletions
@@ -93,6 +93,7 @@
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { adminAPI } from '@/api/admin'
import { extractApiErrorMessage } from '@/utils/apiError'
import type { BatchUpdateUserLimitsRequest } from '@/api/admin/users'
import { useAppStore } from '@/stores/app'
import BaseDialog from '@/components/common/BaseDialog.vue'
@@ -203,9 +204,7 @@ const handleSubmit = async () => {
emit('close')
} catch (error: any) {
appStore.showError(
error.response?.data?.message
|| error.response?.data?.detail
|| t('admin.users.bulkLimits.failed')
extractApiErrorMessage(error, t('admin.users.bulkLimits.failed'))
)
} finally {
submitting.value = false
@@ -59,6 +59,27 @@ describe('BulkEditUserModal', () => {
vi.restoreAllMocks()
})
it.each([
[{ message: 'Selected users are no longer available' }, 'Selected users are no longer available'],
[{ response: { data: { message: 'Legacy message' } } }, 'Legacy message'],
[{ response: { data: { detail: 'Legacy detail' } } }, 'Legacy detail'],
[{}, 'admin.users.bulkLimits.failed'],
])('shows API error details and allows retry after failure', async (error, expected) => {
vi.spyOn(window, 'confirm').mockReturnValue(true)
batchUpdateLimits.mockRejectedValueOnce(error)
const wrapper = mountModal()
await wrapper.get('[data-test="enable-concurrency"]').trigger('click')
await wrapper.get('[data-test="concurrency-input"]').setValue('5')
await wrapper.get('form').trigger('submit')
await flushPromises()
expect(showError).toHaveBeenCalledWith(expected)
expect(wrapper.emitted('close')).toBeUndefined()
expect(wrapper.emitted('success')).toBeUndefined()
expect(wrapper.get('[data-test="submit"]').attributes('disabled')).toBeUndefined()
wrapper.unmount()
})
it('disables submission until at least one enabled field has a value', async () => {
const wrapper = mountModal()