test: retry transient phase3 PDA requests
This commit is contained in:
@@ -74,17 +74,22 @@ export function stableLoadedCartonMarks(items) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function request(context, method, path, body, headers = {}) {
|
async function request(context, method, path, body, headers = {}) {
|
||||||
try {
|
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||||
const response = await fetch(`${context.options.gateway}${path}`, {
|
try {
|
||||||
|
const response = await fetch(`${context.options.gateway}${path}`, {
|
||||||
method,
|
method,
|
||||||
headers: { Accept: 'application/json', Authorization: `Bearer ${context.pdaToken && /\/pda-loading\/tasks\/\d+/.test(path) && !/\/assign(?:\?|$)/.test(path) ? context.pdaToken : context.token}`, ...(body === undefined ? {} : { 'Content-Type': 'application/json; charset=utf-8' }), ...headers },
|
headers: { Accept: 'application/json', Authorization: `Bearer ${context.pdaToken && /\/pda-loading\/tasks\/\d+/.test(path) && !/\/assign(?:\?|$)/.test(path) ? context.pdaToken : context.token}`, ...(body === undefined ? {} : { 'Content-Type': 'application/json; charset=utf-8' }), ...headers },
|
||||||
body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(60_000),
|
body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(60_000),
|
||||||
})
|
})
|
||||||
const raw = await response.text(); let payload = null
|
const raw = await response.text(); let payload = null
|
||||||
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,
|
||||||
|
|||||||
Reference in New Issue
Block a user