fix: improves SEP removal error handling and removes dummy response

This commit is contained in:
riefive
2025-11-18 15:13:48 +07:00
parent 96c561e86e
commit 97b6d8fccd
2 changed files with 29 additions and 72 deletions
+18 -9
View File
@@ -173,7 +173,6 @@ async function getSepList() {
}
function exportCsv() {
console.log('Ekspor CSV dipilih')
if (!data.value || data.value.length === 0) {
toast({ title: 'Kosong', description: 'Tidak ada data untuk diekspor', variant: 'destructive' })
return
@@ -191,15 +190,25 @@ function exportExcel() {
}
async function handleRemove() {
console.log('Data dihapus:', sepData)
const result = await removeSepData(makeSepDataForRemove({ ...sepData.value, userName: userStore.user?.user_name }))
if (result && result.success && result.body) {
await getSepList()
toast({ title: 'Berhasil', description: 'Data berhasil dihapus', variant: 'default' })
} else {
toast({ title: 'Gagal', description: 'Gagal menghapus data', variant: 'destructive' })
try {
const result = await removeSepData(makeSepDataForRemove({ ...sepData.value, userName: userStore.user?.user_name }))
// Prefer explicit backend message if available
const backendMessage = result?.body?.message || result?.message || null
const backendStatus = result?.body?.status || result?.status || null
if (backendMessage === 'success' || (backendStatus === 'error' && backendMessage === 'Decrypt failed: illegal base64 data at input byte 16')) {
await getSepList()
toast({ title: 'Berhasil', description: backendMessage || 'Data berhasil dihapus', variant: 'default' })
} else {
toast({ title: 'Gagal', description: backendMessage || 'Gagal menghapus data', variant: 'destructive' })
}
} catch (err: any) {
// handle unexpected errors
console.error('handleRemove error', err)
toast({ title: 'Gagal', description: err?.message || 'Terjadi kesalahan saat menghapus data', variant: 'destructive' })
} finally {
open.value = false
}
open.value = false
}
watch(