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.
karan BadhwarWeb Development Techdegree Student 13,921 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,676 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.