From 8588b054525cce77c2f335407551c40324d54e6e Mon Sep 17 00:00:00 2001 From: krank Date: Tue, 31 Aug 2021 14:33:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=BB=86=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/utils/request.js | 41 +++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/web/src/utils/request.js b/web/src/utils/request.js index ac9946b2..9498482a 100644 --- a/web/src/utils/request.js +++ b/web/src/utils/request.js @@ -81,19 +81,34 @@ service.interceptors.response.use( }, error => { closeLoading() - ElMessageBox.confirm(` -

检测到接口错误${error}

-

错误码500:此类错误内容常见于后台panic,如果影响您正常使用可强制登出清理缓存

-

错误码404:此类错误多为接口未注册(或未重启)或者请求路径(方法)与api路径(方法)不符

- `, '接口报错', { - dangerouslyUseHTMLString: true, - distinguishCancelAndClose: true, - confirmButtonText: '清理缓存', - cancelButtonText: '取消' - }) - .then(() => { - store.commit('user/LoginOut') - }) + switch (error.response.status) { + case 500: + ElMessageBox.confirm(` +

检测到接口错误${error}

+

错误码 500 :此类错误内容常见于后台panic,请先查看后台日志,如果影响您正常使用可强制登出清理缓存

+ `, '接口报错', { + dangerouslyUseHTMLString: true, + distinguishCancelAndClose: true, + confirmButtonText: '清理缓存', + cancelButtonText: '取消' + }) + .then(() => { + store.commit('user/LoginOut') + }) + break + case 404: + ElMessageBox.confirm(` +

检测到接口错误${error}

+

错误码 404 :此类错误多为接口未注册(或未重启)或者请求路径(方法)与api路径(方法)不符--如果为自动化代码请检查是否存在空格

+ `, '接口报错', { + dangerouslyUseHTMLString: true, + distinguishCancelAndClose: true, + confirmButtonText: '我知道了', + cancelButtonText: '取消' + }) + break + } + return error } )