fix: 下载文件时(responseType === 'blob')需要判断下载失败(返回json而非二进制)的情况
This commit is contained in:
parent
6716e0c979
commit
77cd005f15
@ -18,6 +18,7 @@
|
||||
|
||||
- 字典项为空时getDict方法无限调用接口(无奈兼容 不给字典item本来就是错误用法)
|
||||
- 表格排序翻页会丢失排序参数
|
||||
- 下载文件时(responseType === 'blob')需要判断下载失败(返回json而非二进制)的情况
|
||||
|
||||
**OTHERS**
|
||||
|
||||
|
@ -140,7 +140,7 @@ function createRequestClient(baseURL: string) {
|
||||
);
|
||||
|
||||
client.addResponseInterceptor<HttpResponse>({
|
||||
fulfilled: (response) => {
|
||||
fulfilled: async (response) => {
|
||||
const encryptKey = (response.headers || {})['encrypt-key'];
|
||||
if (encryptKey) {
|
||||
/** RSA私钥解密 拿到解密秘钥的base64 */
|
||||
@ -164,8 +164,25 @@ function createRequestClient(baseURL: string) {
|
||||
// 不进行任何处理,直接返回
|
||||
// 用于页面代码可能需要直接获取code,data,message这些信息时开启
|
||||
if (!isTransformResponse) {
|
||||
/**
|
||||
* 需要判断下载二进制的情况 正常是返回二进制 报错会返回json
|
||||
* 当type为blob且content-type为application/json时 则判断已经下载出错
|
||||
* 不能直接去判断blob的类型 因为下载json类型和报错的类型是一致的 需要从响应头判断
|
||||
*/
|
||||
if (
|
||||
response.config.responseType === 'blob' &&
|
||||
response.headers['content-type']?.includes?.('application/json')
|
||||
) {
|
||||
// 这时候的data为blob类型
|
||||
const blob = response.data as unknown as Blob;
|
||||
// 拿到字符串转json对象
|
||||
response.data = JSON.parse(await blob.text());
|
||||
// 然后按正常逻辑执行下面的代码(判断业务状态码)
|
||||
} else {
|
||||
// 不为blob 直接返回
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
const axiosResponseData = response.data;
|
||||
if (!axiosResponseData) {
|
||||
|
Loading…
Reference in New Issue
Block a user