Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
res => {
const apiRes = res.data
switch (+apiRes.code) {
case codeStatus.NOTFOUND:
document.title = '404 - 找不到页面'
flag && iView.LoadingBar.error()
// 可以在这里直接设置跳转到 404 页面,已经不需要啦,在组件中已经设置,为了不改变 url,实现转发的效果
// router.push({name: 'error'})
break
case codeStatus.UNAUTHORIZED:
store.dispatch('user/CLEARUSER')
sessionStorage.clear()
iView.Message.error(apiRes.message)
flag && iView.LoadingBar.finish()
router.push({name: 'login'})
break
default:
flag && iView.LoadingBar.finish()
break
}
return apiRes
},
async error => {
}, function (error) {
iView.LoadingBar.error()
// 403 状态执行页面跳转,其余状态不跳转
if (error.response.status === 403) {
toLogin(conf)
return Promise.reject(error.response.data)
} else {
iView.Message.error({
content: error.response.data.message ? error.response.data.message : '系统异常!',
duration: 10,
closable: true
})
return Promise.reject(error.response.data)
}
})
created: function () {
this.$Notice = iView.Notice
this.$Message = iView.Message
}
})
HTTP.interceptors.response.use(null, function(error) {
let response = error.response;
if(response == undefined) {
iView.Message.error(error.message);
return Promise.reject(error.message);
}
let status = response.status;
if (status === 400) {
iView.Message.error(response.data);
/*Object.keys(response.data).forEach(function(key) {
iView.Message.error(response.data[key][0]);
});*/
} else if (status === 401) {
iView.Message.error("Unauthorized user!");
} else if (status === 404) {
if(response.request.responseURL.indexOf('login?ReturnUrl=') > 0) {
status = iView.Message.error("Login again");
return;
export function noticeError (err, tip = '发生了错误', duration = 10) {
log.error(err)
tip = `${_.escape(tip)}: ${err.message}`
iView.Message.error({
content: tip,
duration,
closable: true
})
}