Skip to content

Commit 86e93e7

Browse files
committed
fix: #22 error.response
1 parent e4c85b9 commit 86e93e7

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/utils/request.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@ const service = axios.create({
1313

1414
const err = (error) => {
1515
if (error.response) {
16-
if (error.status === 403) {
17-
notification.error({ message: '拒绝访问', description: '无权限,拒绝访问' })
16+
let data = error.response.data
17+
const token = Vue.ls.get(ACCESS_TOKEN)
18+
if (error.response.status === 403) {
19+
notification.error({ message: 'Forbidden', description: data.message})
1820
}
19-
if (error.status === 401) {
20-
notification.error({ message: '未授权', description: '授权验证失败' })
21-
store.dispatch('Logout').then(() => {
22-
location.reload()
23-
})
21+
if (error.response.status === 401) {
22+
notification.error({ message: 'Unauthorized', description: 'Authorization verification failed' })
23+
if (token) {
24+
store.dispatch('Logout').then(() => {
25+
setTimeout(() => {
26+
window.location.reload()
27+
}, 1500)
28+
})
29+
}
2430
}
2531
}
2632
return Promise.reject(error)
2733
};
2834

29-
// request 拦截器
35+
// request interceptor
3036
service.interceptors.request.use(config => {
3137
const token = Vue.ls.get(ACCESS_TOKEN)
3238
if (token) {
@@ -35,7 +41,7 @@ service.interceptors.request.use(config => {
3541
return config
3642
}, err)
3743

38-
// response 拦截器
44+
// response interceptor
3945
service.interceptors.response.use((response) => {
4046
return response.data
4147
}, err)

0 commit comments

Comments
 (0)