test: harden admin acceptance fixtures
This commit is contained in:
@@ -562,8 +562,10 @@ async function multipartRequest(context, path, data) {
|
||||
}
|
||||
|
||||
async function requestWithHeaders(context, method, path, body, extraHeaders) {
|
||||
try {
|
||||
const response = await fetch(`${context.options.gateway}${path}`, {
|
||||
let lastResponse = null
|
||||
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||
try {
|
||||
const response = await fetch(`${context.options.gateway}${path}`, {
|
||||
method,
|
||||
headers: {
|
||||
Accept: 'application/json', Authorization: `Bearer ${context.token}`,
|
||||
@@ -574,15 +576,20 @@ async function requestWithHeaders(context, method, path, body, extraHeaders) {
|
||||
const content = await response.text()
|
||||
let payload = null
|
||||
try { payload = content ? JSON.parse(content) : null } catch { /* Preserve only a bounded error string. */ }
|
||||
return {
|
||||
lastResponse = {
|
||||
method, path, http: response.status, body: payload,
|
||||
raw: payload === null ? content.slice(0, 500) : null,
|
||||
requestId: payload?.requestId || response.headers.get('x-request-id'),
|
||||
traceId: payload?.traceId || response.headers.get('x-trace-id'),
|
||||
}
|
||||
if (lastResponse.http !== 0 || attempt === 3) return lastResponse
|
||||
} catch (error) {
|
||||
lastResponse = { method, path, http: 0, body: null, raw: error instanceof Error ? error.message : String(error), requestId: null, traceId: null }
|
||||
if (attempt === 3) return lastResponse
|
||||
}
|
||||
} catch (error) {
|
||||
return { method, path, http: 0, body: null, raw: error instanceof Error ? error.message : String(error), requestId: null, traceId: null }
|
||||
await new Promise((resolve) => setTimeout(resolve, 400 * attempt))
|
||||
}
|
||||
return lastResponse
|
||||
}
|
||||
|
||||
async function updateConfirmedPackageCount(context, measurementPath, itemId, body) {
|
||||
|
||||
Reference in New Issue
Block a user