Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Asynchronous Programming with JavaScript Exploring Async/Await Error Handling with try...catch

a sync and await error

async-await.js:53 TypeError: Cannot read property 'source' of undefined at async-await.js:38 at Array.map (<anonymous>) at generateHTML (async-await.js:34) (anonymous) @ async-await.js:53

btn.addEventListener('click', (event) => { event.target.textContent = "Loading..."; getPeopleInSpace(astrosUrl) .then(generateHTML) .catch(e => { peopleList.innerHTML = '<h3> something went wrong</h3>'; console.error(e); }) .finally( () => event.target.remove() ) });

1 Answer

If you look through past comments on this course, you'll find this is due to one of the astronaut's names being ambiguous in the wiki api. person.name = 'Andrew Morgan ' has multiple results on wiki. Try this to get you through the course. Add a condition in the generateHTML method

function generateHTML(data) { data.map(person => { const section = document.createElement('section'); peopleList.appendChild(section); if (person.type === 'standard') { // Add this condition section.innerHTML = <img src=${person.thumbnail.source}> <span>${person.craft}</span> <h2>${person.title}</h2> <p>${person.description}</p> <p>${person.extract}</p> ; } }); }