fix
This commit is contained in:
@@ -35,8 +35,28 @@ import axios, {
|
||||
// 3. 响应拦截器
|
||||
instance.interceptors.response.use(
|
||||
(response: AxiosResponse) => {
|
||||
const cfg = response.config as RequestConfig
|
||||
if (cfg.rawResponse) {
|
||||
return response
|
||||
}
|
||||
// 二进制流:只返回 data,且勿对 Blob 访问 .status
|
||||
if (cfg.responseType === 'blob' || cfg.responseType === 'arraybuffer') {
|
||||
const body = response.data as unknown
|
||||
if (body instanceof Blob) return body
|
||||
if (typeof body === 'string') {
|
||||
return new Blob([body], {
|
||||
type: (response.headers['content-type'] as string) || 'application/octet-stream',
|
||||
})
|
||||
}
|
||||
if (body instanceof ArrayBuffer) {
|
||||
return new Blob([body], {
|
||||
type: (response.headers['content-type'] as string) || 'application/octet-stream',
|
||||
})
|
||||
}
|
||||
return body
|
||||
}
|
||||
// 统一处理响应数据格式[2](@ref)
|
||||
if (response.data.status === 401) {
|
||||
if (response.data?.status === 401) {
|
||||
// token过期处理
|
||||
SafeStorage.clearAppStorage();
|
||||
window.location.href = "/auth/login";
|
||||
@@ -59,6 +79,8 @@ import axios, {
|
||||
interface RequestConfig extends AxiosRequestConfig {
|
||||
data?: unknown;
|
||||
needWorkspace?: boolean;
|
||||
/** 为 true 时响应拦截器返回完整 AxiosResponse(用于 blob 等需自行取 data 的场景) */
|
||||
rawResponse?: boolean;
|
||||
}
|
||||
|
||||
export const request = {
|
||||
|
||||
Reference in New Issue
Block a user