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

Promises don't handle a 404 response

The fix shown in other comments is an appalling bodge-up. Students should NOT be encouraged to use this example just to get through the tutorial. Treehouse - you need to address the fact that a 404 is breaking the project during these lessons. The generateHTML function is passed an undefined item in the object array, breaking the app when data.map tries to read the value person.thumbnail.source.

Wrapping the html builder in a conditional stops the app breaking, but then there's the unhandled 404 sitting in the console. We need to know how to deal with situations like that too. This problem meant that it took me three days to complete the Promises tutorials because I spent so much time looking for ways to handle the 404 properly. (I didn't find one because, technically, it's not an error).

function generateHTML(data) {
  data.map( person => {
    if(person.title !== "Not found."){
      const section = document.createElement('section');
      peopleList.appendChild(section);
      section.innerHTML = `
        <img src=${person.thumbnail.source}>
        <span>${person.craft}</span>
        <h2>${person.title}</h2>
        <p>${person.description}</p>
        <p>${person.extract}</p>
      `;
    }
  });
}

I'm a little disillusioned with Treehouse at this point, these tutorials are clearly not covering everything we need to know. The plethora of comments on this issue, none of which have a good professional answer, is proof that nothing has been done to fix the failing. The lack of a supplementary video to address it also tells me Treehouse aren't interested in customer feedback.

1 Answer

Steven Parker
Steven Parker
231,141 Points

A video might be a rather big ask, particularly since the issue is due to two 3rd-party API's having a disagreement about spelling. :see_no_evil:

But perhaps something in the "Teacher's Notes" would be in order. Have you tried sending a suggestion directly to the Support folks?

Couldn't disagree more, it's a real world issue that any coder would have to handle. therefore should be featured "somewhere". I didn't ask Treehouse to get in touch with the API owners, just acknowledge that their tutorial is broken and offer a fix. It's hard to learn coding if, no matter how correct your code is, all you see are errors in the console.

Steven Parker
Steven Parker
231,141 Points

I based my suggestion on how this other video got an "Important Update" in the "Teacher's Notes" when it was no longer accurate.