feat: 增加步骤 7 从步骤 6 重启的错误标记构建逻辑,优化错误处理
This commit is contained in:
+37
-16
@@ -1010,6 +1010,7 @@ function isVerificationMailPollingError(error) {
|
||||
}
|
||||
|
||||
const STEP7_RESTART_FROM_STEP6_ERROR_CODE = 'STEP7_RESTART_FROM_STEP6';
|
||||
const STEP7_RESTART_FROM_STEP6_MARKER_PATTERN = /^STEP7_RESTART_FROM_STEP6::([^:]+)::(.*)$/;
|
||||
|
||||
function createStep7RestartFromStep6Error(details = {}) {
|
||||
const { reason = 'unknown', url = '' } = details || {};
|
||||
@@ -1023,15 +1024,35 @@ function createStep7RestartFromStep6Error(details = {}) {
|
||||
return error;
|
||||
}
|
||||
|
||||
function getStep7RestartFromStep6Error(result) {
|
||||
if (!result?.restartFromStep6) {
|
||||
function parseStep7RestartFromStep6Marker(message) {
|
||||
const normalized = getErrorMessage(message);
|
||||
const match = normalized.match(STEP7_RESTART_FROM_STEP6_MARKER_PATTERN);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
return createStep7RestartFromStep6Error(result);
|
||||
|
||||
return {
|
||||
reason: match[1] || 'unknown',
|
||||
url: match[2] || '',
|
||||
};
|
||||
}
|
||||
|
||||
function getStep7RestartFromStep6Error(result) {
|
||||
if (result?.restartFromStep6) {
|
||||
return createStep7RestartFromStep6Error(result);
|
||||
}
|
||||
|
||||
const parsed = parseStep7RestartFromStep6Marker(result?.error);
|
||||
if (!parsed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createStep7RestartFromStep6Error(parsed);
|
||||
}
|
||||
|
||||
function isStep7RestartFromStep6Error(error) {
|
||||
return error?.code === STEP7_RESTART_FROM_STEP6_ERROR_CODE;
|
||||
return error?.code === STEP7_RESTART_FROM_STEP6_ERROR_CODE
|
||||
|| Boolean(parseStep7RestartFromStep6Marker(error));
|
||||
}
|
||||
|
||||
function isStep7RecoverableError(error) {
|
||||
@@ -2564,10 +2585,6 @@ async function requestVerificationCodeResend(step) {
|
||||
payload: {},
|
||||
});
|
||||
|
||||
if (result && result.error) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
|
||||
if (step === 7) {
|
||||
const restartError = getStep7RestartFromStep6Error(result);
|
||||
if (restartError) {
|
||||
@@ -2575,6 +2592,10 @@ async function requestVerificationCodeResend(step) {
|
||||
}
|
||||
}
|
||||
|
||||
if (result && result.error) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
|
||||
return Date.now();
|
||||
}
|
||||
|
||||
@@ -2657,10 +2678,6 @@ async function submitVerificationCode(step, code) {
|
||||
payload: { code },
|
||||
});
|
||||
|
||||
if (result && result.error) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
|
||||
if (step === 7) {
|
||||
const restartError = getStep7RestartFromStep6Error(result);
|
||||
if (restartError) {
|
||||
@@ -2668,6 +2685,10 @@ async function submitVerificationCode(step, code) {
|
||||
}
|
||||
}
|
||||
|
||||
if (result && result.error) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
|
||||
return result || {};
|
||||
}
|
||||
|
||||
@@ -2882,15 +2903,15 @@ async function runStep7Attempt(state) {
|
||||
payload: {},
|
||||
});
|
||||
|
||||
if (prepareResult && prepareResult.error) {
|
||||
throw new Error(prepareResult.error);
|
||||
}
|
||||
|
||||
const restartError = getStep7RestartFromStep6Error(prepareResult);
|
||||
if (restartError) {
|
||||
throw restartError;
|
||||
}
|
||||
|
||||
if (prepareResult && prepareResult.error) {
|
||||
throw new Error(prepareResult.error);
|
||||
}
|
||||
|
||||
await addLog(`步骤 7:正在打开${mail.label}...`);
|
||||
|
||||
const alive = await isTabAlive(mail.source);
|
||||
|
||||
@@ -658,12 +658,17 @@ function isSignupPasswordErrorPage() {
|
||||
return matchesAuthTimeoutErrorPage(/\/create-account\/password(?:[/?#]|$)/i);
|
||||
}
|
||||
|
||||
function buildStep7RestartFromStep6Marker(reason, url = location.href) {
|
||||
return `STEP7_RESTART_FROM_STEP6::${reason || 'unknown'}::${url || ''}`;
|
||||
}
|
||||
|
||||
function getStep7RestartFromStep6Signal() {
|
||||
if (!isLoginPage() || !matchesAuthTimeoutErrorPage(/\/log-in(?:[/?#]|$)/i)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
error: buildStep7RestartFromStep6Marker('login_timeout_error_page', location.href),
|
||||
restartFromStep6: true,
|
||||
reason: 'login_timeout_error_page',
|
||||
url: location.href,
|
||||
|
||||
Reference in New Issue
Block a user