fix(web-probe): expose auth retries and proxy public hwlab (#708)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -406,6 +406,8 @@ async function authenticate(browserContext) {
|
||||
const maxDelayMs = 5000;
|
||||
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
||||
const retryDelayMs = attempt < maxAttempts ? Math.min(maxDelayMs, initialDelayMs * (2 ** (attempt - 1))) : 0;
|
||||
const retryLabel = attempt + "/" + maxAttempts;
|
||||
await writeHeartbeat({ status: terminalStatus, auth: { phase: "api-login", retryAttempt: attempt, retryMaxAttempts: maxAttempts, lastRetryLabel: retryLabel, retryDelayMs: 0, retryExhausted: false, valuesRedacted: true } }).catch(() => {});
|
||||
try {
|
||||
const response = await browserContext.request.post(loginUrl, {
|
||||
data: { username, password },
|
||||
@@ -418,7 +420,7 @@ async function authenticate(browserContext) {
|
||||
attempt,
|
||||
retryAttempt: attempt,
|
||||
retryMaxAttempts: maxAttempts,
|
||||
retryLabel: attempt + "/" + maxAttempts,
|
||||
retryLabel,
|
||||
retryDelayMs: retryable && attempt < maxAttempts ? retryDelayMs : 0,
|
||||
method: "api",
|
||||
status: response.status(),
|
||||
@@ -429,6 +431,7 @@ async function authenticate(browserContext) {
|
||||
valuesRedacted: true,
|
||||
};
|
||||
attempts.push(item);
|
||||
await writeHeartbeat({ status: terminalStatus, auth: { phase: "api-login", lastRetryLabel: item.retryLabel, retryAttempt: item.retryAttempt, retryMaxAttempts: item.retryMaxAttempts, retryDelayMs: item.retryDelayMs, lastStatus: item.status, lastStatusText: item.statusText, retryable: item.retryable, cookiePresent: item.cookiePresent, retryExhausted: false, valuesRedacted: true } }).catch(() => {});
|
||||
if (response.ok() && cookieState.cookiePresent) {
|
||||
return {
|
||||
ok: true,
|
||||
@@ -454,7 +457,7 @@ async function authenticate(browserContext) {
|
||||
attempt,
|
||||
retryAttempt: attempt,
|
||||
retryMaxAttempts: maxAttempts,
|
||||
retryLabel: attempt + "/" + maxAttempts,
|
||||
retryLabel,
|
||||
retryDelayMs: retryable && attempt < maxAttempts ? retryDelayMs : 0,
|
||||
method: "api",
|
||||
status: 0,
|
||||
@@ -465,6 +468,8 @@ async function authenticate(browserContext) {
|
||||
cookieNames: [],
|
||||
valuesRedacted: true,
|
||||
});
|
||||
const item = attempts[attempts.length - 1] || null;
|
||||
await writeHeartbeat({ status: terminalStatus, auth: { phase: "api-login", lastRetryLabel: item?.retryLabel || retryLabel, retryAttempt: attempt, retryMaxAttempts: maxAttempts, retryDelayMs: item?.retryDelayMs ?? 0, lastStatus: item?.status ?? 0, lastStatusText: item?.statusText ?? "request-error", retryable, cookiePresent: false, retryExhausted: false, lastError: item?.error || null, valuesRedacted: true } }).catch(() => {});
|
||||
if (!retryable) break;
|
||||
}
|
||||
if (attempt < maxAttempts && attempts[attempts.length - 1]?.retryable === true) await sleep(retryDelayMs);
|
||||
@@ -489,6 +494,7 @@ async function authenticate(browserContext) {
|
||||
lastError: last?.error || null,
|
||||
valuesRedacted: true,
|
||||
};
|
||||
await writeHeartbeat({ status: terminalStatus, auth: { phase: "api-login", lastRetryLabel: failure.lastRetryLabel, retryAttempt: attempts.length, retryMaxAttempts: maxAttempts, retryDelayMs: 0, lastStatus: failure.status, lastStatusText: failure.statusText, retryable: failure.retryable, cookiePresent: failure.cookiePresent, retryExhausted: failure.retryExhausted, lastError: failure.lastError, valuesRedacted: true } }).catch(() => {});
|
||||
const error = new Error(authFailureMessage(failure));
|
||||
error.webProbeAuth = failure;
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user