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('身份验证失败,请重新登录。');