>  Q&A  >  본문

Vue.js axios 인터셉터가 401에 응답합니다.

콘솔에 다음 오류가 표시됩니다. Uncaught (in promise) TypeError: Cannot read property of undef at eval (read 'message'). 이것은 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粉066725148P粉066725148205일 전365

모든 응답(1)나는 대답할 것이다

  • P粉345302753

    P粉3453027532024-03-28 11:31:44

    추가해 보세요response.messageerror.response.message 替换为 response.statusTexterror.response.statusText.

    회신하다
    0
  • 취소회신하다