diff --git a/src/utils/request.js b/src/utils/request.js index 78b1496..1fcf829 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -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