Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const errorHandler = (error) => {
if (error.response) {
const data = error.response.data
// 从 localstorage 获取 token
const token = storage.get(ACCESS_TOKEN)
if (error.response.status === 403) {
notification.error({
message: 'Forbidden',
description: data.message
})
}
if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
notification.error({
message: 'Unauthorized',
description: 'Authorization verification failed'
})
if (token) {
store.dispatch('Logout').then(() => {
setTimeout(() => {
window.location.reload()
}, 1500)
})
}
}
}
return Promise.reject(error)
}
.catch((e) => {
notification.error({
message: e.message,
description: 'Failed to request user information. Please try again!'
})
setTimeout(() => {
console.log('should re-login')
store.dispatch('Login')
}, 3000)
})
} else if (to.path === '/user/login' && !config.useSSO && store.getters.roles.length !== 0) {
.catch((e) => {
console.log(e)
notification.error({
message: '错误',
description: '请求用户信息失败,请重试'
})
setTimeout(() => {
store.dispatch('Logout')
}, 3000)
})
} else if (to.path === '/user/login' && !config.useSSO && store.getters.roles.length !== 0) {
const err = (error) => {
console.log(error)
if (error.response) {
const data = error.response.data
if (error.response.status === 403) {
notification.error({
message: 'Forbidden',
description: data.message
})
}
if (error.response.status === 401 &&
!(data.result && data.result.isLogin)) {
notification.error({
message: 'Unauthorized',
description: 'Authorization verification failed'
})
}
} else {
error = i18n.t('network.error')
}
return Promise.reject(error)
}
.catch((e) => {
notification.error({
message: '错误',
description: e
})
})
}