feat: enhance error handling in CRUD operations and adjust encounterId type in SEP creation

This commit is contained in:
riefive
2025-12-02 14:24:08 +07:00
parent 64efb0dee7
commit ebac2244ac
3 changed files with 42 additions and 11 deletions
+20 -10
View File
@@ -444,7 +444,7 @@ export function useIntegrationSepEntry() {
navigateTo('/integration/bpjs-vclaim/sep')
}
if (menu === 'save-sep-number') {
const sourcePath = route.query['source-path'] || '' as any
const sourcePath = route.query['source-path'] || ('' as any)
navigateTo({ path: sourcePath, query: { 'sep-number': value.sepNumber || '' } })
}
if (menu === 'save-sep') {
@@ -491,19 +491,29 @@ export function useIntegrationSepEntry() {
createSep(payload)
.then((res) => {
const body = res?.body
const code = body?.metaData?.code
const message = body?.metaData?.message
if (code && code !== '200') {
toast({ title: 'Gagal', description: message || 'Gagal membuat SEP', variant: 'destructive' })
const success = res?.success
if (success) {
const body = res?.body
const code = body?.metaData?.code
const message = body?.metaData?.message
if (code && code !== '200') {
toast({ title: 'Gagal', description: message || 'Gagal membuat SEP', variant: 'destructive' })
return
}
toast({ title: 'Berhasil', description: 'SEP berhasil dibuat', variant: 'default' })
if (!!resourcePath.value) {
navigateTo({ path: resourcePath.value, query: { 'sep-number': body?.response?.sep?.noSep || '-' } })
return
}
navigateTo('/integration/bpjs-vclaim/sep')
return
}
toast({ title: 'Berhasil', description: 'SEP berhasil dibuat', variant: 'default' })
if (!!resourcePath.value) {
navigateTo({ path: resourcePath.value, query: { 'sep-number': body?.response?.sep?.noSep || '-' } })
const error = res?.error
if (error) {
const errorMessage = error?.message ? `${error?.message}` : 'Sep gagal dibuat'
toast({ title: 'Gagal', description: errorMessage, variant: 'destructive' })
return
}
navigateTo('/integration/bpjs-vclaim/sep')
})
.catch((err) => {
console.error('Failed to save SEP:', err)
+21
View File
@@ -5,6 +5,9 @@ export async function create(path: string, data: any, name: string = 'item') {
const resp = await xfetch(path, 'POST', data)
const result: any = {}
result.success = resp.success
if (resp.status_code !== 200) {
result.error = { ...resp.error }
}
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
@@ -29,6 +32,9 @@ export async function getList(path: string, params: any = null, name: string = '
const resp = await xfetch(url, 'GET')
const result: any = {}
result.success = resp.success
if (resp.status_code !== 200) {
result.error = { ...resp.error }
}
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
@@ -53,6 +59,9 @@ export async function getDetail(path: string, id: number | string, name: string
const resp = await xfetch(`${path}/${id}${paramStr}`, 'GET')
const result: any = {}
result.success = resp.success
if (resp.status_code !== 200) {
result.error = { ...resp.error }
}
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
@@ -66,6 +75,9 @@ export async function update(path: string, id: number | string, data: any, name:
const resp = await xfetch(`${path}/${id}`, 'PATCH', data)
const result: any = {}
result.success = resp.success
if (resp.status_code !== 200) {
result.error = { ...resp.error }
}
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
@@ -79,6 +91,9 @@ export async function updateCustom(path: string, data: any, name: string = 'item
const resp = await xfetch(`${path}`, 'PATCH', data)
const result: any = {}
result.success = resp.success
if (resp.status_code !== 200) {
result.error = { ...resp.error }
}
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
@@ -92,6 +107,9 @@ export async function remove(path: string, id: number | string, name: string = '
const resp = await xfetch(`${path}/${id}`, 'DELETE')
const result: any = {}
result.success = resp.success
if (resp.status_code !== 200) {
result.error = { ...resp.error }
}
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
@@ -105,6 +123,9 @@ export async function removeCustom(path: string, data: any, name: string = 'item
const resp = await xfetch(`${path}`, 'DELETE', data)
const result: any = {}
result.success = resp.success
if (resp.status_code !== 200) {
result.error = { ...resp.error }
}
result.body = (resp.body as Record<string, any>) || {}
return result
} catch (error) {
+1 -1
View File
@@ -17,7 +17,7 @@ export function create(data: any) {
let payload: any = data
if (isNew && data?.encounterId) {
payload = {
encounter_id: data.encounterId || null,
encounter_id: Number(data.encounterId) || 0,
requestPayload: data?.request ? JSON.stringify({ request: data.request }) : null,
}
} else {