JavaScript Asynchronous Programming with JavaScript Understanding Promises From Callbacks to Promises

S G
S G
6,243 Points

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

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,369 Points

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.

S G
S G
6,243 Points

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

Thank you