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 Handling Errors

Samuel Kleos
seal-mask
.a{fill-rule:evenodd;}techdegree
Samuel Kleos
Front End Web Development Techdegree Student 13,307 Points

My .catch() method is not throwing an error in the console.

See my snapshot: https://w.trhou.se/ba289en5fb

ChatGPT thinks it should log to console just fine but I've removed the catch method with a mistyped URL and my console looks the same:

GET https://dog.ceo/api/basdfa/image/random 404
GET http://port-80-hv98rdr4ku.treehouse-app.com/No%20route%20found%20for 404 (Not Found)       

1 Answer

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Hi Samuel Kleos, the reason it is not going into your catch method is because from the promise's point of view, it has still fulfilled. If you log out the response in the then method (which you can see is where the promise goes instead of the catch), you will see that the response ok property is false, and the status property is 404. It would be up to you to code out the logic at this point inside the then method to throw an error so that the catch method would then be called.

Samuel Kleos
seal-mask
.a{fill-rule:evenodd;}techdegree
Samuel Kleos
Front End Web Development Techdegree Student 13,307 Points

I am trying my best to understand what you mean by "from the promise's point of view, it has still fulfilled".

Are you trying to say that the promise was resolved and it was not rejected? Is that why my catch method was not activated?

I'm guessing this is what you mean because you said "log out the response in the then method (which you can see is where the promise goes instead of the catch)".

I'm guessing that the response as you've stated "goes" to the then() method instead of the catch() method because the promise hit the resolve() instead of the reject() when it is loading?

Please tell me if I am understanding your response correctly.

Thank you..