Skip to content

Wrong error type in httpclient doc #34748

@AlexNedo

Description

@AlexNedo

📚 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
0139b11#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentfreq2: mediumstate: has PRtype: bug/fix

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions