retry merchant transfer submission on transport failure
This commit is contained in:
@@ -184,9 +184,27 @@ async function verifyTransfer(context, token, orders) {
|
||||
const created = await merchant(context, token, 'POST', '客户创建仓储转运申请', TRANSFER, body)
|
||||
const transferNo = id(created.data?.transferNo)
|
||||
if (transferNo && created.data?.status === 'DRAFT') {
|
||||
const submitted = await merchant(context, token, 'POST',
|
||||
`${TRANSFER}/${encodeURIComponent(transferNo)}/submit`)
|
||||
if (submitted.data) created.data = submitted.data
|
||||
// The overseas gateway occasionally drops a connection while the submit
|
||||
// request is still being processed. Retry transport failures only, then
|
||||
// reconcile from the authoritative detail before asserting the state.
|
||||
let submitted = null
|
||||
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||
const response = await context.requestOverseas('POST',
|
||||
`${TRANSFER}/${encodeURIComponent(transferNo)}/submit`, undefined, {}, token)
|
||||
if (response?.http === 0 && attempt < 3) {
|
||||
await new Promise(resolve => setTimeout(resolve, 800 * attempt))
|
||||
continue
|
||||
}
|
||||
const data = context.apiSuccess(MODULE, '客户提交仓储转运申请', response, trace(response), OPTIONS)
|
||||
submitted = { response, data }
|
||||
break
|
||||
}
|
||||
if (submitted?.data) created.data = submitted.data
|
||||
if (created.data?.status !== 'PENDING_REVIEW') {
|
||||
const reconciled = await merchant(context, token, 'GET', '提交后回查仓储转运申请',
|
||||
`${TRANSFER}/${encodeURIComponent(transferNo)}`)
|
||||
if (reconciled.data) created.data = reconciled.data
|
||||
}
|
||||
}
|
||||
context.assert(MODULE, '仓储转运申请进入合法待审核状态且绑定本轮来源订单', created.response,
|
||||
Boolean(transferNo) && created.data?.status === 'PENDING_REVIEW'
|
||||
|
||||
Reference in New Issue
Block a user