From 67574732c76a55e6f8a09a000e752f6624923241 Mon Sep 17 00:00:00 2001 From: wuhongjian Date: Fri, 21 Oct 2022 16:45:53 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/utils/request.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/front/src/utils/request.js b/front/src/utils/request.js index 03239f01..dfcce28a 100644 --- a/front/src/utils/request.js +++ b/front/src/utils/request.js @@ -161,14 +161,14 @@ instance.interceptors.response.use( console.log('接口error', error) if (loadingInstance) loadingInstance.close() - const { response, message } = error + const { response, myMessage } = error if (error.response) { console.log('接口返回', response) console.log('接口返回headers', response.headers) console.log('接口返回REDIRECT', response.headers.redirect) const { status, data } = response - handleCode(status, data.msg || message, response.headers.redirect) + handleCode(status, data.msg || myMessage, response.headers.redirect) if (response.headers.token) { setAccessToken(response.headers.token) } @@ -179,18 +179,18 @@ instance.interceptors.response.use( return Promise.reject(error) } else { - let { message } = error - if (message === 'Network Error') { - message = '后端接口连接异常' + // let { message } = error + if (error.message === 'Network Error') { + error.message = '后端接口连接异常' } - if (message.includes('timeout')) { - message = '后端接口请求超时' + if (error.message.includes('timeout')) { + error.message = '后端接口请求超时' } - if (message.includes('Request failed with status code')) { - const code = message.substr(message.length - 3) - message = '后端接口' + code + '异常' + if (error.message.includes('Request failed with status code')) { + const code = error.message.substr(error.message.length - 3) + error.message = '后端接口' + code + '异常' } - message.error(message || `后端接口未知异常`) + message.error(error.message || `后端接口未知异常`) return Promise.reject(error) } }