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 trialS G
6,243 PointsI 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
KRIS NIKOLAISEN
54,971 PointsHe 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.
S G
6,243 PointsSo what are the errors that statusText provides? Couldn't find a list
Thank you