fix(jd-database): 红框整体上移——筛选行+批量工具栏提到页面最顶通栏(他窗在飞件代提交);网络层失败显式中文提示
This commit is contained in:
@@ -10,7 +10,28 @@ import { userNotice } from '../api/user-notice.ts'
|
||||
/** 失败条上那个按钮的字样:必须是「重试」而不是一句「知道了」——撤入口同时得是出口。 */
|
||||
export const LOAD_FAILURE_RETRY_LABEL = '重试'
|
||||
|
||||
/** 从 axios 错误 / Error / 字符串里取后端给的原因;取不到、或原文不是中文时返回空串。 */
|
||||
/** 网络层失败(请求没到服务器就断了)给用户的中文提示。2026-11-21 线上实录:用户代理
|
||||
* 链路抖动成批掐断 TLS 连接(当天全服 29 条「连接未完成即断」记录全部来自该用户的两个
|
||||
* 出口 IP),axios 拿到英文 "Network Error" 按 userNotice 口径被滤空 ⇒ 界面只剩页面
|
||||
* 兜底文案,用户看不出是网络问题、更不知道该重试还是该找人。这里显式补一句。 */
|
||||
export const NETWORK_FAILURE_DETAIL = '网络连接中断,请检查网络后重试'
|
||||
|
||||
/** axios 错误且没有 response = 网络层失败(连接被掐断/超时/DNS),服务端根本没回话。
|
||||
* 只认 axios 形状(code 为网络错误码,或带 config+isAxiosError 标记);普通 Error 没有
|
||||
* response 不算(走原有 message 解析)。 */
|
||||
function isNetworkLevelError(error: unknown): boolean {
|
||||
if (!error || typeof error !== 'object') return false
|
||||
const record = error as Record<string, unknown>
|
||||
if (record.response !== undefined) return false
|
||||
const code = typeof record.code === 'string' ? record.code : ''
|
||||
if (code === 'ECONNABORTED' || code === 'ERR_NETWORK' || code === 'ETIMEDOUT' || code === 'ECONNRESET') {
|
||||
return true
|
||||
}
|
||||
return record.isAxiosError === true && record.config !== undefined
|
||||
}
|
||||
|
||||
/** 从 axios 错误 / Error / 字符串里取后端给的原因;取不到、或原文不是中文时返回空串。
|
||||
* 例外:axios 网络层失败(无 response)不算「取不到原因」,给中文网络提示。 */
|
||||
export function failureDetail(error: unknown): string {
|
||||
const data = (error as { response?: { data?: unknown } } | undefined)?.response?.data
|
||||
if (data && typeof data === 'object') {
|
||||
@@ -20,6 +41,7 @@ export function failureDetail(error: unknown): string {
|
||||
if (typeof value === 'string' && value.trim()) return userNotice(value, '')
|
||||
}
|
||||
}
|
||||
if (isNetworkLevelError(error)) return NETWORK_FAILURE_DETAIL
|
||||
if (error instanceof Error && error.message.trim()) return userNotice(error.message, '')
|
||||
if (typeof error === 'string' && error.trim()) return userNotice(error, '')
|
||||
return ''
|
||||
|
||||
Reference in New Issue
Block a user