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!
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
karan BadhwarWeb Development Techdegree Graduate 18,135 Points
Somebody Please help
I need to finish this lesson now, I spent 6 hours, watched the same video over a dozen time. I have couple of questions,
2) - why do we need to return an object on the last .then on getProfiles?, we are already returning the last .then() in an object as we already know the .then() method returns a promise object, then why are putting that in an object?
3)-.catch(err => console.log('Error found', err)) , how the err is getting a reject message from? and the 'Error found ' message does it have anything to do with the parameter?
Caleb Kemp12,754 Points
I think the main thing that is giving you difficulty is that you are missing the idea of the lesson. response.json() works, and there is nothing wrong with it. However, the teacher wanted to show us another (potentially better) way of handling that functionality using the Fetch API. Most of the changes needed in the code are because the Fetch API functions a little differently than response.json(). That being said,
This concept may be a little more difficult to understand. The catch function only gets triggered if an error occurs which it will pass to the catch block. Do you see where it says the first "err" in
catch(err => console.log('Error found', err))? That is the variable name that the error is getting passed to. So, when the rest of the function
console.log('Error found', err)), it will print the message "Error found" + the message stored in the err variable.
Don't worry about it, everyone has concepts that give them trouble sometimes. Hope that helps.