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) } }