Visitar URL original
fix(common): incorrect error type for XHR errors in `TestRequest` by devversion · Pull Request #36082 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20220206224747/https://github.com/angular/angular/pull/36082
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): incorrect error type for XHR errors in TestRequest #36082

Conversation

@devversion
Copy link
Member

@devversion devversion commented Mar 16, 2020

Currently the HttpClient always wraps errors from XHR requests, but
the underlying errors are always of type ProgressEvent, or don't have
a native error if the status code is just indicating failure (e.g. 404).

This behavior does not match in the TestRequest class provided by
@angular/common/http/testing where errors are considered being
of type ErrorEvent. This is incorrect because ErrorEvents provide
information for errors in scripts or files which are evaluated. Since
the HttpClient never evaluates scripts/files, and also since XHR requests
clearly are documented to emit ProgressEvent's, we should change the
TestSupport to retrieve such ProgressEvent's instead of incompatible
objects of type ErrorEvent.

Resources:

Related to: #34748.

@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch 6 times, most recently from 98ec624 to 7ecec02 Mar 17, 2020
@devversion devversion marked this pull request as ready for review Mar 17, 2020
@pullapprove pullapprove bot requested a review from kara Mar 17, 2020
@ngbot ngbot bot added this to the needsTriage milestone Mar 17, 2020
@devversion devversion requested a review from alxhub Mar 17, 2020
alxhub
alxhub approved these changes Apr 9, 2020
@pullapprove pullapprove bot requested a review from IgorMinar Apr 9, 2020
@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch 2 times, most recently from cd1d50f to 6c52c2f May 7, 2020
@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch from 6c52c2f to 5acd0f2 May 20, 2020
@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch from 5acd0f2 to 58698c6 Jun 10, 2020
Copy link
Member

@jelbourn jelbourn left a comment

LGTM - does anything need to go into the deprecation doc?

Reviewed-for: public-api

@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch 2 times, most recently from bffca6e to 3cac51b Jun 22, 2020
@mary-poppins

This comment has been hidden.

@ngbot ngbot bot added this to the Backlog milestone Nov 18, 2021
@mary-poppins
Copy link

@mary-poppins mary-poppins commented Nov 18, 2021

@devversion devversion marked this pull request as ready for review Nov 18, 2021
@devversion
Copy link
Member Author

@devversion devversion commented Nov 18, 2021

@jessicajaniuk I've just resurrected this PR. Addressed feedback etc. I just need one more public API approval.

Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

LGTM 🍪

reviewed-for: public-api

@jessicajaniuk
Copy link
Contributor

@jessicajaniuk jessicajaniuk commented Nov 18, 2021

I'll run a TGP to make sure we're safe in google3 with this change.

alxhub
alxhub approved these changes Nov 18, 2021
Currently the `HttpClient` always wraps errors from XHR requests, but
the underlying errors are always of type `ProgressEvent`, or don't have
a native error if the status code is just indicating failure (e.g. 404).

This behavior does not match in the `TestRequest` class provided by
`@angular/common/http/testing` where errors are considered being
of type `ErrorEvent`. This is incorrect because `ErrorEvent`s provide
information for errors in scripts or files which are evaluated. Since
the `HttpClient` never evaluates scripts/files, and also since XHR requests
clearly are documented to emit `ProgressEvent`'s, we should change the
`TestSupport` to retrieve such `ProgressEvent`'s instead of incompatible
objects of type `ErrorEvent`.

In favor of having a deprecation period, we keep supporting `ErrorEvent`
in the `TestRequest.error` signature. Eventually, we can remove this
signature in the future.

Resources:
  * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/error_event
  * https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent
  * https://xhr.spec.whatwg.org/#event-xhr-errpr

Related to: angular#34748.

DEPRECATED: `TestRequest` from `@angular/common/http/testing` no longer
accepts `ErrorEvent` when simulating XHR errors. Instead instances of
`ProgressEvent` should be passed, matching with the native browser behavior.
@jessicajaniuk jessicajaniuk force-pushed the fix/common-http-testing-type-error-event-properly branch from 3e29972 to 9598e7c Nov 19, 2021
@jessicajaniuk
Copy link
Contributor

@jessicajaniuk jessicajaniuk commented Nov 19, 2021

@devversion Can you rebase this and repush? It seems to fail to build in google3 now.

@mary-poppins
Copy link

@mary-poppins mary-poppins commented Nov 19, 2021

@jessicajaniuk
Copy link
Contributor

@jessicajaniuk jessicajaniuk commented Nov 19, 2021

The TGP passed.

@jessicajaniuk
Copy link
Contributor

@jessicajaniuk jessicajaniuk commented Nov 19, 2021

This PR was merged into the repository by commit 489cf42.

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Dec 20, 2021

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 20, 2021
dimakuba added a commit to dimakuba/angular that referenced this issue Dec 28, 2021
…gular#36082)

Currently the `HttpClient` always wraps errors from XHR requests, but
the underlying errors are always of type `ProgressEvent`, or don't have
a native error if the status code is just indicating failure (e.g. 404).

This behavior does not match in the `TestRequest` class provided by
`@angular/common/http/testing` where errors are considered being
of type `ErrorEvent`. This is incorrect because `ErrorEvent`s provide
information for errors in scripts or files which are evaluated. Since
the `HttpClient` never evaluates scripts/files, and also since XHR requests
clearly are documented to emit `ProgressEvent`'s, we should change the
`TestSupport` to retrieve such `ProgressEvent`'s instead of incompatible
objects of type `ErrorEvent`.

In favor of having a deprecation period, we keep supporting `ErrorEvent`
in the `TestRequest.error` signature. Eventually, we can remove this
signature in the future.

Resources:
  * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/error_event
  * https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent
  * https://xhr.spec.whatwg.org/#event-xhr-errpr

Related to: angular#34748.

DEPRECATED: `TestRequest` from `@angular/common/http/testing` no longer
accepts `ErrorEvent` when simulating XHR errors. Instead instances of
`ProgressEvent` should be passed, matching with the native browser behavior.

PR Close angular#36082
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.