From 0f8c9aec2503dcbe1828ab9b54ab07e31baee45e Mon Sep 17 00:00:00 2001 From: Acyco Date: Mon, 10 Mar 2025 22:08:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8E=E5=8F=B0=E6=8A=9B=E5=87=BA=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=BB=8D=E7=BB=A7=E7=BB=AD=E4=B8=8B=E8=BD=BD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=B8=8D=E8=BF=9B=E8=A1=8C=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=20(#53)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/http.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/utils/http.ts b/src/utils/http.ts index 8feb0d1..c956053 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -65,7 +65,24 @@ http.interceptors.response.use( const { data } = response const { success, code, msg } = data - if (response.request.responseType === 'blob' || success) { + if (response.request.responseType === 'blob') { + const contentType = data.type + if (contentType.startsWith('application/json')) { + const reader = new FileReader() + reader.readAsText(data) + reader.onload = () => { + const { success, msg } = JSON.parse(reader.result as string) + if (!success) { + handleError(msg) + } + } + return Promise.reject(msg) + } else { + return response + } + } + + if (success) { return response }