Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Asynchronous Programming with JavaScript Understanding Promises Perform Cleanup With finally()

So frustrating. I don't see the profiles, and get 'TypeError: Cannot read property 'source' of undefined'

In the last video this error came up, even though my code matches this video. The same error exists in this stage so this video was mostly pointless.

3 Answers

Justin Keiser
Justin Keiser
15,145 Points

I don't know how to fix it yet but the error boils down to some of the folks in space have the same name as multiple wikipedia entries. I noticed this earlier when there were empty section elements. https://teamtreehouse.com/community/same-code-and-still-getting-an-error

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hey Daniel Cranney and Justin Keiser, in the generateHTML function, where you're adding the img element, try changing that line to one of these, depending on which section you're on:

<img src="${data.thumbnail ? data.thumbnail.source : ''}">

Or

<img src="${person.thumbnail ? person.thumbnail.source : ''}">

The problem is that not all of the results have a thumbnail property. So you have to check that the property exists before trying to use it, and if it doesn't exist, you can just pass an empty string to the src attribute. :thumbsup:

Justin Keiser
Justin Keiser
15,145 Points

Thanks Robert Manolis, I actually found that answer somewhere else. It works, but I'd love to know how to resolve the wikipedia problem so all of the people in space display. I've checked and all of the folks currently in space have articles, they just share names with other people. This wasn't the case when the tutorial was made.

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

Ahh, I see what you mean, Justin Keiser. You're talking about a way to handle the disambiguation pages. Yeah, that could be done. After checking out the docs for the wikipedia API, one way that comes to mind would involve reworking the getProfiles function. After making the initial wikiUrl + person.name request, you'd loop over the results, and for the ones that have a type property with a value of 'disambiguation', you'd make another request, but with a slightly different URL. Instead of page/summary/, you'd use page/related, and that would give you an array of non disambiguation pages. So you'd loop over those results, and work out a way to grab the one you want, like the one that has a description property that includes the term cosmonaut or astronaut. Something like that should work. :thumbsup: