# 优化登录过期提示

This commit is contained in:
xianfuxing 2018-08-02 19:13:16 +08:00
parent a0fc07809a
commit e2af5b3fa6
1 changed files with 17 additions and 9 deletions

View File

@ -64,16 +64,24 @@ service.interceptors.response.use(
console.log('err' + error)
if (error && error.response) { // 401 token 过期
if (error.response.status === 401) {
MessageBox.confirm('登录过期已被登出,取消继续留在该页面,或者重新登录', '确定登出', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
store.dispatch('FedLogOut').then(() => {
location.reload() // 为了重新实例化vue-router对象 避免bug
const ret = error.response
const url = ret.config.url
const target = '/users/info'
console.log(url.indexOf(target))
// check if 401 get /api/users/info/ then redirect to /login
if (url.indexOf(target) === -1) {
MessageBox.confirm('登录过期已被登出,取消继续留在该页面,或者重新登录', '确定登出', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
store.dispatch('FedLogOut').then(() => {
location.reload() // 为了重新实例化vue-router对象 避免bug
})
})
})
return Promise.reject(error)
return Promise.reject(error)
}
error.message = ret.data.detail
}
// check login error response from server api
const login_error = error.response.data.non_field_errors