From a941374b328f09c7d7fc2c4662cc071d72c6a9ac Mon Sep 17 00:00:00 2001 From: "335260830@qq.com" <335260830@qq.com> Date: Tue, 6 Jul 2021 21:57:03 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90feat:=E6=B7=BB=E5=8A=A0=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=8B=A6=E6=88=AA=E7=9A=84=E9=94=99=E8=AF=AF=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=A0=81=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index de538cd..ded350c 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,4 +1,4 @@ -import Axios, { AxiosRequestConfig, AxiosResponse } from 'axios' +import Axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios' import { message } from 'ant-design-vue' // import router from '@/router' // import qs from 'qs' @@ -6,6 +6,13 @@ import store from '@/store' import { setToken, getToken, removeToken } from '@/utils/auth' import { refreshToken } from '@/api/system/user' import NProgress from 'nprogress' +const RESPONSE_STATUS = { + OK: 200, + NOT_LOGIN: 401, + NO_PERMISSON: 403, + NOT_FOUND: 404, + SERVER_ERROR: 500, +} interface CustomAxiosRequestConfig extends AxiosRequestConfig { hideLoading?: boolean @@ -74,11 +81,22 @@ service.interceptors.response.use( return Promise.resolve(data) }, - (error: { message: string }) => { + (error: AxiosError) => { NProgress.done() - message.destroy() - message.error('网络异常') + const response = Object.assign({}, error.response) + if (response) { + switch (response.status) { + case RESPONSE_STATUS.NOT_FOUND: + message.error('没找到接口信息') + break + case RESPONSE_STATUS.SERVER_ERROR: + message.error('系统异常') + break + default: + message.error(`连接错误-${response.status}`) + } + } return Promise.reject(error) }, ) -- Gitee