2
votes

I am getting this error on console: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'message') at eval. 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)
    }
})
1
The error is here: error.response.message must actually be error.message. I think. Have to know about the API response to be 100% sure. - adibro500
@adibro500 I did this and it gave: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'status') at eval, on console. I used the same (error.message.response) at my previous project and it worked but i dont know why it is not working again. Thanks for your answer. - Mirkhon Kuziyev
Can you provide me the screenshot of the network -> response/preview tab? That will be easier. You can check that too yourself. - adibro500
@adibro500 interesting this is i am not getting any response in network, error is shown only in console and that suprised me. Maybe i should review my codes from begining - Mirkhon Kuziyev
The reason can be that the page is getting redirected to the /login route. Please try to check the Preserve Log option in the network tab and try. - adibro500

1 Answers

2
votes

Try to replace response.message and error.response.message by response.statusText and error.response.statusText.