feat: 增强错误处理逻辑,添加 Cloudflare 风控和网络超时拦截提示

This commit is contained in:
QLHazyCoder
2026-04-18 20:54:00 +08:00
parent 82471af931
commit 609cdeaeb5
12 changed files with 440 additions and 17 deletions
+44 -4
View File
@@ -65,7 +65,7 @@ function createRecoveryApi(state) {
test('auth page recovery detects retry page state', () => {
const state = {
clickCount: 0,
pageText: 'Something went wrong. Operation timed out.',
pageText: 'Something went wrong. Please try again.',
retryVisible: true,
};
const api = createRecoveryApi(state);
@@ -77,13 +77,15 @@ test('auth page recovery detects retry page state', () => {
assert.equal(Boolean(snapshot), true);
assert.equal(snapshot.retryEnabled, true);
assert.equal(snapshot.titleMatched, true);
assert.equal(snapshot.detailMatched, true);
assert.equal(snapshot.detailMatched, false);
assert.equal(snapshot.maxCheckAttemptsBlocked, false);
assert.equal(snapshot.operationTimedOutBlocked, false);
});
test('auth page recovery clicks retry and waits until page recovers', async () => {
const state = {
clickCount: 0,
pageText: 'Something went wrong. Operation timed out.',
pageText: 'Something went wrong. Please try again.',
retryVisible: true,
};
const api = createRecoveryApi(state);
@@ -107,7 +109,7 @@ test('auth page recovery clicks retry and waits until page recovers', async () =
test('auth page recovery can click retry twice before page recovers', async () => {
const state = {
clickCount: 0,
pageText: 'Something went wrong. Operation timed out.',
pageText: 'Something went wrong. Please try again.',
retryVisible: true,
onClick(currentState) {
if (currentState.clickCount >= 2) {
@@ -135,3 +137,41 @@ test('auth page recovery can click retry twice before page recovers', async () =
assert.equal(state.clickCount, 2);
assert.equal(state.retryVisible, false);
});
test('auth page recovery throws cloudflare security blocked error on max_check_attempts page', async () => {
const state = {
clickCount: 0,
pageText: 'Something went wrong. max_check_attempts reached.',
retryVisible: true,
};
const api = createRecoveryApi(state);
await assert.rejects(
() => api.recoverAuthRetryPage({
logLabel: '步骤 7:检测到登录超时报错,正在点击“重试”恢复当前页面',
pathPatterns: [/\/log-in(?:[/?#]|$)/i],
step: 7,
timeoutMs: 1000,
}),
/CF_SECURITY_BLOCKED::/
);
});
test('auth page recovery throws network timeout block error on operation timed out page', async () => {
const state = {
clickCount: 0,
pageText: 'Something went wrong. Operation timed out.',
retryVisible: true,
};
const api = createRecoveryApi(state);
await assert.rejects(
() => api.recoverAuthRetryPage({
logLabel: '步骤 7:检测到登录超时报错,正在点击“重试”恢复当前页面',
pathPatterns: [/\/log-in(?:[/?#]|$)/i],
step: 7,
timeoutMs: 1000,
}),
/NETWORK_TIMEOUT_BLOCKED::/
);
});