Surface real API error on warranty refresh

Error messages nest at data.data.error.message; the warranty handlers read one
level too shallow so every failure showed a generic "failed". Read the correct
path (with fallbacks) so the actual reason shows - e.g. Dell's rate-limit
cooldown - and confirm the pulled coverage on a successful refresh.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-07-09 16:22:46 -04:00
parent 08a9290071
commit 9cc7cc7529

View File

@@ -228,6 +228,14 @@ function openModal(item = null) {
}
function closeModal() { showModal.value = false; editing.value = null }
// API errors nest the message at data.data.error.message (see error_response).
function apiError(err, fallback) {
return err.response?.data?.data?.error?.message
|| err.response?.data?.error?.message
|| err.response?.data?.message
|| fallback
}
async function save() {
error.value = ''
saving.value = true
@@ -241,7 +249,7 @@ async function save() {
closeModal()
loadData()
} catch (err) {
error.value = err.response?.data?.error?.message || err.response?.data?.message || 'Failed to save'
error.value = apiError(err, 'Failed to save')
} finally {
saving.value = false
}
@@ -253,16 +261,18 @@ async function deleteWarranty(w) {
await warrantyApi.remove(w.warrantyid)
loadData()
} catch (err) {
alert(err.response?.data?.error?.message || 'Failed to delete')
alert(apiError(err, 'Failed to delete'))
}
}
async function refresh(w) {
try {
await warrantyApi.refresh(w.warrantyid)
const response = await warrantyApi.refresh(w.warrantyid)
loadData()
const updated = response.data?.data
if (updated) alert(`Refreshed: ${updated.vendor} - ${updated.servicelevel || 'coverage'} ends ${updated.enddate || 'unknown'}`)
} catch (err) {
alert(err.response?.data?.error?.message || err.response?.data?.message || 'Refresh failed')
alert(apiError(err, 'Refresh failed'))
}
}
</script>