From a0c6969da0f752ed1a404fc8145c1af01fa7bb1d Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 16 Sep 2026 09:45:52 +0800 Subject: [PATCH] fix(frontend): preserve timeout label success toast --- frontend/app/javascript/dashboard/store/utils/api.js | 7 ++++++- .../app/javascript/dashboard/store/utils/specs/api.spec.js | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/app/javascript/dashboard/store/utils/api.js b/frontend/app/javascript/dashboard/store/utils/api.js index d9cde572..22e65dcd 100644 --- a/frontend/app/javascript/dashboard/store/utils/api.js +++ b/frontend/app/javascript/dashboard/store/utils/api.js @@ -133,7 +133,12 @@ const normalizeAPIErrorText = (message, status) => { if (/^(network error|failed to fetch|network request failed)$/i.test(text)) { return '网络连接失败,请检查网络后重试。'; } - if (/timeout|timed out|超时/i.test(text)) { + if ( + /\b(?:timeout|timed out)\b/i.test(text) || + /(?:^|(?:请求|连接|操作|网络|服务|服务器|上游)[^,。!?;;::]{0,8})超时(?:[,。!?;;::]|$)/.test( + text + ) + ) { return '请求超时,请稍后再试。'; } if (/^invalid email or password$/i.test(text)) { diff --git a/frontend/app/javascript/dashboard/store/utils/specs/api.spec.js b/frontend/app/javascript/dashboard/store/utils/specs/api.spec.js index f8e41f64..85437438 100644 --- a/frontend/app/javascript/dashboard/store/utils/specs/api.spec.js +++ b/frontend/app/javascript/dashboard/store/utils/specs/api.spec.js @@ -37,6 +37,12 @@ describe('#parseAPIErrorResponse', () => { expect(parseAPIErrorResponse('Error: 422 Failed')).toBe( '提交的信息有误,请检查后重试。' ); + expect(parseAPIErrorResponse('timeout of 10000ms exceeded')).toBe( + '请求超时,请稍后再试。' + ); + expect(parseAPIErrorResponse('已从会话 ID 14 移除标签 #超时关闭')).toBe( + '已从会话 ID 14 移除标签 #超时关闭' + ); expect( parseAPIErrorResponse(new Error('Request failed with status code 401')) ).toBe('身份验证失败,请重新登录。');