feat: enhance error handling in CRUD operations and adjust encounterId type in SEP creation
This commit is contained in:
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user