Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error response object is undefined #883

Closed
nabs-grg opened this issue May 3, 2017 · 8 comments
Closed

Error response object is undefined #883

nabs-grg opened this issue May 3, 2017 · 8 comments

Comments

@nabs-grg
Copy link

nabs-grg commented May 3, 2017

#### Summary
Hello,

I am making an API HTTP request using axios but i don't get an error object in response. The response for the error comes as undefined and I only get the instance of an error object if I console.log(error).

I have followed the same pattern for error handling which is in the documentation.

Here is the screenshot of the console showing only the instance of error when I do console.log(error).

screen shot 2017-05-03 at 16 44 07

Here is another screenshot showing error.response as undefined.

screen shot 2017-05-03 at 17 16 37

I have 404 as status code also the response body is in the image below.

screen shot 2017-05-03 at 17 08 38

  • axios version: v0.16.1
  • Environment: node v7.7.4, chrome 58, macOS Sierra
@fgiarritiello
Copy link

I have the same problem. Did something change?

@tyleriguchi
Copy link

Hey had this happen to me, the issue is that the api on what a rejected promise returns has changed. Before you did something like this

.catch( (response ) => {
  console.log(response.data.errors)
})

but now you have to do something like this

.catch(  (error) => {
  const response = error.response
  console.log(response.data.errors)
})

I had bumped from something pre v0.10.0 to v0.16.1

@langfordG
Copy link

langfordG commented May 22, 2017

I'm having the exact same issue and found this thread helpful: #383

Likely has to do with a CORS header not being present for that response code.

@nabs-grg
Copy link
Author

Thanks @tyleriguchi and @graysonlangford for the help. And yes the CORS header wasn't present for the response code.

@nelson6e65
Copy link

This is maybe related...

It happens to me that on authenticated (value is set in store.getters.authToken), if I add extra data to axios.interceptors.request, I get the error.

// axios-config.js
import Vue from 'vue'
import axios from 'axios'
import store from '~/store'
import router from '~/router'

axios.interceptors.request.use(request => {
  if (store.getters.authToken) {
    request.headers.common['Authorization'] = `Bearer ${store.getters.authToken}`
  }

  request.data.locale = store.getters.locale // <- EXTRA DATA ATTACHED 

  return request
})
// store/auth.js
// . . .
async fetchUser ({ commit }) {
    try {
      const { data } = await axios.get('/user/current') //  <-- I GET THE ERROR HERE

      commit(types.FETCH_USER_SUCCESS, { user: data })
    } catch (e) {
      console.error(e)
      commit(types.FETCH_USER_FAILURE)
    }
  },

For non successful login it works fine all. I get this error only there (when I try to get the current user). And is gone if I remove the extra data from the interceptors.

So, my problem is then the authToken is set.


I ended up to use cookies to get the locale value in my back-end, but... I don't understand why this happens.

@felix9ia
Copy link

(error) =>{ console.info(error.config); }

@sveinn
Copy link

sveinn commented Jun 12, 2019

For me the thrown error actually was not undefined, it just looked like that in Chrome's dev tools. (Not sure why but if anyone figures it out, please let me know)

@andrade-lucas
Copy link

In my case, I imported axios on a document and created a baseUrl, so I exported it, but when I import that document in another one, it says that can not read property create of undefined

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants