Skip to content

Instantly share code, notes, and snippets.

@eroncardoso88
Last active May 24, 2019 15:45
Show Gist options
  • Save eroncardoso88/f05545acdf8ed28be04e2ae57b3751eb to your computer and use it in GitHub Desktop.
Save eroncardoso88/f05545acdf8ed28be04e2ae57b3751eb to your computer and use it in GitHub Desktop.
Async code getting an undefined result
// final code for openweather.com app
// **********************************
searchData = async () => {
// API call
let data = await fetch(link);
console.log('inside API');
const res = await data.json();
this.parseChecker(res);
};
parseChecker = async (res) => {
if (res !== undefined) {
this.updateFromServer(res);
} else { console.log('error, data is undefined') }
};
updateFromServer = (res) => {
let transitionObject = [...res.list]
const updatedArray = transitionObject.filter(function(city) {
return cities.indexOf(city);
});
console.log(updatedArray);
};
@eroncardoso88
Copy link
Author

eroncardoso88 commented May 23, 2019

edit: issue i had

console.log(teste); // Response {type: "cors", url: "http://api.openweathermap.org/data/2.5/group?id=34…PID=200f283586f507e8c77b876afa998b97&units=metric", redirected: false, status: 200, ok: true, …}
const testeLista = teste.list

I'm trying to use testeLista as an object with the array 'list' on it. But it isn't. This is just the response from the server, not a json object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment