This commit is contained in:
zlwu committed 2026-08-22 09:08:05 +08:00
1 parent 833544def3
commit 16be6fa22d
204 files changed
+455089 -46491

No files matched your search

+49 -9
View File
@@ -88,7 +88,27 @@ dbAxios.interceptors.request.use(async (config: InternalAxiosRequestConfig) => {
})
dbAxios.interceptors.response.use(
(res) => res.data,
async (res) => {
if (res.config.responseType === 'blob') {
const contentType = String(res.headers['content-type'] || '')
if (contentType.includes('application/json')) {
const text = await (res.data as Blob).text()
try {
const json = JSON.parse(text) as { detail?: string; msg?: string }
const message =
typeof json.detail === 'string'
? json.detail
: json.msg || '导出失败'
ElMessage.error(message)
return Promise.reject(new Error(message))
} catch {
/* 非 JSON blob 直出 */
}
}
return res.data
}
return res.data
},
async (err) => {
const status = err.response?.status
const config = err.config as RetryableConfig | undefined
@@ -142,16 +162,36 @@ dbAxios.interceptors.response.use(
const showErrorMessage = config?.showErrorMessage !== false
if (showErrorMessage) {
const detail = err.response?.data?.detail
const message =
typeof detail === 'string'
? detail
: Array.isArray(detail)
? detail.map((x: { msg?: string }) => x.msg).filter(Boolean).join(';')
: err.response?.data?.msg
let message: string | undefined
const data = err.response?.data
if (data instanceof Blob) {
try {
const text = await data.text()
const json = JSON.parse(text) as { detail?: string; msg?: string }
message = typeof json.detail === 'string' ? json.detail : json.msg
} catch {
/* ignore */
}
} else {
const detail = data?.detail
message =
typeof detail === 'string'
? detail
: Array.isArray(detail)
? detail.map((x: { msg?: string }) => x.msg).filter(Boolean).join(';')
: data?.msg
}
ElMessage.error(message || err.message || '网络异常')
}
return Promise.reject(err)
return Promise.reject(
err instanceof Error && err.message
? err
: new Error(
(typeof err.response?.data?.detail === 'string'
? err.response.data.detail
: err.message) || '网络异常'
)
)
}
)