I am trying to use the data I retrieve from an axios call. I get the correct info back in the response but when I try to return response I get undefined in the calling function. Is there a different way to return the response.data to the calling function?
static getRequest(url) {
require('es6-promise').polyfill();
axios({
method: 'get',
url: url,
responseType:'json',
withCredentials: true
})
.then(response => {
console.log(response.data);
return response.data;
})
.catch(error => {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log('___________ERROR RESPONSE__________');
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log('_________ERROR REQUEST_______');
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an
Error
console.log('Error', error.message);
}
console.log('_________ERROR CONFIG_________');
console.log(error.config);
});
}