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 Asynchronous Programming with JavaScript Understanding Promises From Callbacks to Promises

I didn't understand why you need to use xhr.onerror, doesn't statusText provide all the errors?

this line : reject( Error(xhr.statusText) )

vs this line: xhr.onerror = () => reject ( Error('A network error occurred') )

2 Answers

He explains in the video @ 2:15:

Now if at some point there's a network connectivity issue, a status code wouldn't be provided. So let's also use the onerror event handler on the xhr object to reject the promise if the HttpRequest fails due to connectivity issues.

So what are the errors that statusText provides? Couldn't find a list

Thank you