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 trialMarni Ali
4,642 Points404 Error code on API callback for one of the astronauts
Hi there, I may have a problem with the callback of one of the names. I have looked around and some answers I got from the forum said that it is the spelling of the name? Correct me if I am wrong. It was supposed to return 10 objects but I got 9 instead. https://w.trhou.se/6zjjswjbbx
1 Answer
Steven Parker
231,271 PointsThere seem to be to issues here: first, the list is adding a period to the name of one of the people, and this causes the Wiki lookup for that person to fail.
But also, if you look up the Wiki pages by hand, you'll find that for that same person (Sergey Korsakov) you get a disambiguation page instead of the info page the code is expecting. This is because there are two people with similar names in the database.
Adding code to detect and remove stray punctuation would be reasonably simple, but to detect and resolve a disambiguation page would be a much more advanced challenge. But as a quick fix for both issues, you could just check for "Sergey Korsakov." (with the period), and substitute "Sergey Korsakov (cosmonaut)":
btn.addEventListener('click', () => {
getJSON(astrosUrl,(json) => {
json.people.map( person => {
if (person.name == "Sergey Korsakov.") // change bad name to correct one
getJSON(wikiUrl + "Sergey Korsakov (cosmonaut)", generateHTML);
else
getJSON(wikiUrl + person.name, generateHTML);
});
});