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

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 Compare March 17, 2020 11:02
@devversion devversion marked this pull request as ready for review March 17, 2020 11:03
@pullapprove pullapprove bot requested a review from kara March 17, 2020 11:03
@devversion devversion added area: common/http action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release labels Mar 17, 2020
@ngbot ngbot bot added this to the needsTriage milestone Mar 17, 2020
@devversion devversion requested a review from alxhub March 17, 2020 11:04
@pullapprove pullapprove bot requested a review from IgorMinar April 9, 2020 00:07
@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch 2 times, most recently from cd1d50f to 6c52c2f Compare May 7, 2020 13:44
@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch from 6c52c2f to 5acd0f2 Compare May 20, 2020 22:05
@devversion devversion force-pushed the fix/common-http-testing-type-error-event-properly branch from 5acd0f2 to 58698c6 Compare June 10, 2020 19:23
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Compare June 22, 2020 07:06
@mary-poppins

This comment has been minimized.

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

You can preview 3e29972 at https://pr36082-3e29972.ngbuilds.io/.

@devversion devversion marked this pull request as ready for review November 18, 2021 15:14
@devversion
Copy link
Member Author

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

@devversion devversion added target: minor This PR is targeted for the next minor release and removed target: major This PR is targeted for the next major release labels Nov 18, 2021
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🍪

reviewed-for: public-api

@jessicajaniuk
Copy link
Contributor

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

@jessicajaniuk jessicajaniuk added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels 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 Compare November 19, 2021 19:46
@jessicajaniuk
Copy link
Contributor

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

@mary-poppins
Copy link

You can preview 9598e7c at https://pr36082-9598e7c.ngbuilds.io/.

@jessicajaniuk
Copy link
Contributor

The TGP passed.

@jessicajaniuk jessicajaniuk removed the action: presubmit The PR is in need of a google3 presubmit label Nov 19, 2021
@jessicajaniuk
Copy link
Contributor

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

@angular-automatic-lock-bot
Copy link

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 pushed a commit to dimakuba/angular that referenced this pull request 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.
Labels
action: merge The PR is ready for merge by the caretaker aio: preview area: common/http cla: yes target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet