Vue.js axios interceptor responds 401
P粉066725148
P粉066725148 2024-03-27 17:18:17
0
1
437

I get this error on the console: Uncaught (in promise) TypeError: Cannot read property of undefined at eval (read 'message'). This is my code in axios.js:

axiosIns.interceptors.response.use(
response => {
    if (response.message === 'Unauthenticated') {
        window.location = '/login'
    }

    return response
},
error => {
    if (error.response.message === 'Unauthenticated') {
        window.location = '/login'
    } else if (error.response.status === 401) {
        removeUserData()
        return Promise.reject(error)
    }
})

P粉066725148
P粉066725148

reply all(1)
P粉345302753

Try replacing response.message and error.response.message with response.statusText and error.response.statusText.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template