fix: treat missing return records as empty results

This commit is contained in:
2026-09-11 15:01:17 +08:00
parent f7d3a9a73f
commit fdd9302c4d
6 changed files with 69 additions and 11 deletions
+18 -2
View File
@@ -16,6 +16,11 @@ function normalizeItem(item = {}) {
}
}
function isNotFound(error) {
const code = String(error?.code || '').toUpperCase()
return code === 'A0404' || code === '404'
}
export function normalizeReturnReceiptStart(value = {}) {
return {
returnNo: String(value.returnNo || ''),
@@ -54,11 +59,22 @@ export function normalizeReturnReceiptResult(value = {}) {
}
export async function startReturnReceipt(returnNo) {
return normalizeReturnReceiptStart(await overseasRequest('POST', `${BASE}/start`, { returnNo: String(returnNo || '').trim() }))
try {
return normalizeReturnReceiptStart(await overseasRequest('POST', `${BASE}/start`, { returnNo: String(returnNo || '').trim() }))
} catch (error) {
if (isNotFound(error)) return null
throw error
}
}
export async function findReturnSkuCandidates(skuCode) {
return normalizeReturnSkuCandidates(await overseasRequest('POST', `${BASE}/sku-candidates`, { skuCode: String(skuCode || '').trim() }))
const normalizedSkuCode = String(skuCode || '').trim()
try {
return normalizeReturnSkuCandidates(await overseasRequest('POST', `${BASE}/sku-candidates`, { skuCode: normalizedSkuCode }))
} catch (error) {
if (isNotFound(error)) return normalizeReturnSkuCandidates({ skuCode: normalizedSkuCode, candidates: [] })
throw error
}
}
export async function confirmReturnReceipt(request) {