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 Asynchronous JavaScript with Callbacks Implement a Callback

404 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
Steven Parker
220,425 Points

There 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);
    });
});