From cb7a0f6405ab6a26d008221c8d7f7fa1cff706c2 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Sat, 24 Feb 2024 17:30:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20mockReponse=20?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=20headers=20=E6=97=B6=E7=9A=84=E6=8A=A5?= =?UTF-8?q?=E9=94=99=20Close:=20#9565=20(#9583)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/utils/api.ts | 2 +- packages/amis-core/src/utils/attachmentAdpator.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/amis-core/src/utils/api.ts b/packages/amis-core/src/utils/api.ts index e3f7004b89c..9b30f158be2 100644 --- a/packages/amis-core/src/utils/api.ts +++ b/packages/amis-core/src/utils/api.ts @@ -368,7 +368,7 @@ export function responseAdaptor(ret: fetcherResult, api: ApiObject) { // 返回内容是 string,说明 content-type 不是 json,这时可能是返回了纯文本或 html if (typeof data === 'string') { - const contentType = (ret.headers as any)['content-type'] || ''; + const contentType = (ret.headers as any)?.['content-type'] || ''; // 如果是文本类型就尝试解析一下 if ( ret.headers && diff --git a/packages/amis-core/src/utils/attachmentAdpator.ts b/packages/amis-core/src/utils/attachmentAdpator.ts index 7146de15cdb..10a32363224 100644 --- a/packages/amis-core/src/utils/attachmentAdpator.ts +++ b/packages/amis-core/src/utils/attachmentAdpator.ts @@ -38,7 +38,7 @@ export function attachmentAdpator( } } - let type = response.headers['content-type']; + let type = response.headers?.['content-type']; let blob = response.data.toString() === '[object Blob]' ? response.data