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

Daniel Cranney
Daniel Cranney
10,393 Points

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
12,280 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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
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
12,280 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
seal-mask
.a{fill-rule:evenodd;}techdegree
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: