Wrong error type in httpclient doc
See original GitHub issue📚 Docs or angular.io bug report
Description
A type was changed in a recent commit in angular which is not yet represented in the docs.
What’s the affected URL?**
https://angular.io/guide/http#getting-error-details
Reproduction Steps**
In the code snippet app/config/config.service.ts there is this line:
if (error.error instanceof ErrorEvent)
In case of a network error (or similar like a CORS error) the error property of the HttpErrorResponse is should be according to the docs an ErrorEvent. But in my tests always seems to be a ProgressEvent.
In this recent commit https://github.com/angular/angular/commit/0139b11227fdd93983a8c6bd870d579d798fa244#diff-26683cfb34fa97883213282055aef1e7 in the file packages/common/http/src/xhr.ts the type of the error property of the returned HttpErrorResponse was changed from ErrorEvent to ProgressEvent.
Unfortunately unlike ErrorEvent the ProgressEvent has no message property. It is only usable as a indicator for a network error. The message property of the HttpErrorResponse itself has to be queried to retrieve a human readable error message.
The behaviour can be tested in https://stackblitz.com/edit/error-handling-httpclient?file=src%2Fapp%2Fuser.service.ts
I am using Angular 8.2.14
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
@wildsalarian Thanks for this issue. I think this has always been an issue because the
HttpClientnever emitted anErrorEvent, but instead always usedProgressEvent. It was just incorrectly assumed thatErrorEventwill be returned (which has been flagged as incorrect by TypeScript in 0139b11)https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/error_event describes
erroris of typeProgressEvent, so I think we should change:ProgressEventin theinstanceofcheck (seen in this guide)TestRequestto returnProgressEventinstead ofErrorEvent(which is incorrect).This is an interesting question: https://stackoverflow.com/questions/51451508/why-is-a-progressevent-object-passed-to-a-javascript-ajax-error-event-handler.
@devversion Now that #36082 was merged, this can probably be closed?