Browse Source

错误码报错细分

main
krank 3 years ago
parent
commit
8588b05452
  1. 41
      web/src/utils/request.js

41
web/src/utils/request.js

@ -81,19 +81,34 @@ service.interceptors.response.use(
},
error => {
closeLoading()
ElMessageBox.confirm(`
<p>检测到接口错误${error}</p>
<p>错误码500此类错误内容常见于后台panic如果影响您正常使用可强制登出清理缓存</p>
<p>错误码404此类错误多为接口未注册或未重启或者请求路径方法与api路径方法不符</p>
`, '接口报错', {
dangerouslyUseHTMLString: true,
distinguishCancelAndClose: true,
confirmButtonText: '清理缓存',
cancelButtonText: '取消'
})
.then(() => {
store.commit('user/LoginOut')
})
switch (error.response.status) {
case 500:
ElMessageBox.confirm(`
<p>检测到接口错误${error}</p>
<p>错误码<span style="color:red"> 500 </span>panic使</p>
`, '接口报错', {
dangerouslyUseHTMLString: true,
distinguishCancelAndClose: true,
confirmButtonText: '清理缓存',
cancelButtonText: '取消'
})
.then(() => {
store.commit('user/LoginOut')
})
break
case 404:
ElMessageBox.confirm(`
<p>检测到接口错误${error}</p>
<p>错误码<span style="color:red"> 404 </span>api--</p>
`, '接口报错', {
dangerouslyUseHTMLString: true,
distinguishCancelAndClose: true,
confirmButtonText: '我知道了',
cancelButtonText: '取消'
})
break
}
return error
}
)

Loading…
Cancel
Save