test: retry transient phase3 PDA requests

This commit is contained in:
2026-09-24 00:57:47 +08:00
parent d5d3364275
commit ead27a6a11
@@ -74,6 +74,7 @@ export function stableLoadedCartonMarks(items) {
} }
async function request(context, method, path, body, headers = {}) { async function request(context, method, path, body, headers = {}) {
for (let attempt = 1; attempt <= 3; attempt += 1) {
try { try {
const response = await fetch(`${context.options.gateway}${path}`, { const response = await fetch(`${context.options.gateway}${path}`, {
method, method,
@@ -84,7 +85,11 @@ async function request(context, method, path, body, headers = {}) {
try { payload = raw ? JSON.parse(raw) : null } catch { /* bounded raw evidence */ } try { payload = raw ? JSON.parse(raw) : null } catch { /* bounded raw evidence */ }
return { method, path, http: response.status, body: payload, raw: payload === null ? raw.slice(0, 500) : null, return { method, path, http: response.status, body: payload, raw: payload === null ? raw.slice(0, 500) : null,
requestId: payload?.requestId || response.headers.get('x-request-id'), traceId: payload?.traceId || response.headers.get('x-trace-id') } requestId: payload?.requestId || response.headers.get('x-request-id'), traceId: payload?.traceId || response.headers.get('x-trace-id') }
} catch (error) { return { method, path, http: 0, body: null, raw: String(error), requestId: null, traceId: null } } } catch (error) {
if (attempt === 3) return { method, path, http: 0, body: null, raw: String(error), requestId: null, traceId: null }
await new Promise((resolve) => setTimeout(resolve, 250 * attempt))
}
}
} }
export async function uploadEvidence(context, taskId, warehouseId, evidenceType, expectedVersion, keySuffix, export async function uploadEvidence(context, taskId, warehouseId, evidenceType, expectedVersion, keySuffix,